Skip to content

Commit

Permalink
feat: moving blog from swa to container apps
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Dec 15, 2022
1 parent eb7863c commit 3ec2b26
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 15 deletions.
4 changes: 1 addition & 3 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ services:

blog:
project: packages/blog
language: ts
host: staticwebapp
dist: .
host: containerapp
41 changes: 30 additions & 11 deletions infra/app/blog.bicep
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
param environmentName string
param location string = resourceGroup().location
param applicationInsightsName string = ''
param serviceName string = 'blog'
param cmsUrl string
param containerAppsEnvironmentName string
param containerRegistryName string
param imageName string = ''
param name string

module web '../core/host/staticwebapps.bicep' = {
name: 'static-sites-resources-${serviceName}'
module app '../core/host/container-app.bicep' = {
name: '${serviceName}-container-app-module'
params: {
environmentName: environmentName
location: location
environmentName: name
serviceName: serviceName
applicationInsightsName: applicationInsightsName
additionalAppSettings: {
NEXT_PUBLIC_STRAPI_API_URL: cmsUrl
}
location: location
containerAppsEnvironmentName: containerAppsEnvironmentName
containerRegistryName: containerRegistryName
env: [
{
name: 'APPLICATIONINSIGHTS_CONNECTION_STRING'
value: applicationInsights.properties.ConnectionString
}
{
name: 'NEXT_PUBLIC_STRAPI_API_URL'
value: cmsUrl
}
]
imageName: !empty(imageName) ? imageName : 'nginx:latest'
targetPort: 80
}
}

output WEB_BLOG_NAME string = web.name
output WEB_BLOG_URI string = web.outputs.uri
resource applicationInsights 'Microsoft.Insights/components@2020-02-02' existing = {
name: applicationInsightsName
}

output WEB_BLOG_IDENTITY_PRINCIPAL_ID string = app.outputs.identityPrincipalId
output WEB_BLOG_NAME string = app.outputs.name
output WEB_BLOG_URI string = app.outputs.uri
output WEB_BLOG_IMAGE_NAME string = app.outputs.imageName
8 changes: 7 additions & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ module blog 'app/blog.bicep' = {
scope: rg
params: {
cmsUrl: cms.outputs.SERVICE_BLOG_CMS_URI
environmentName: environmentName
containerAppsEnvironmentName: !empty(containerAppsEnvironmentName) ? containerAppsEnvironmentName : '${abbrs.appManagedEnvironments}${resourceToken}'
containerRegistryName: !empty(containerRegistryName) ? containerRegistryName : '${abbrs.containerRegistryRegistries}${resourceToken}'
name: 'blog'
applicationInsightsName: monitoring.outputs.applicationInsightsName
location: location
}
}
Expand All @@ -131,3 +134,6 @@ output AZURE_LOCATION string = location
output AZURE_TENANT_ID string = tenant().tenantId
output WEB_PORTAL_URI string = web.outputs.WEB_PORTAL_URI
output WEB_BLOG_URI string = blog.outputs.WEB_BLOG_URI
output AZURE_CONTAINER_ENVIRONMENT_NAME string = containerApps.outputs.containerAppsEnvironmentName
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = containerApps.outputs.containerRegistryEndpoint
output AZURE_CONTAINER_REGISTRY_NAME string = containerApps.outputs.containerRegistryName
26 changes: 26 additions & 0 deletions packages/blog-cms/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM node:16-alpine as build
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add build-base gcc autoconf automake zlib-dev libpng-dev vips-dev && rm -rf /var/cache/apk/* > /dev/null 2>&1
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./package-lock.json ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN npm install --production
WORKDIR /opt/app
COPY ./ .
RUN npm run build


FROM node:16-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk add vips-dev
RUN rm -rf /var/cache/apk/*
ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/app
COPY --from=build /opt/node_modules ./node_modules
ENV PATH /opt/node_modules/.bin:$PATH
COPY --from=build /opt/app ./
EXPOSE 1337
CMD ["npm", "run","start"]
52 changes: 52 additions & 0 deletions packages/blog/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Install dependencies only when needed
FROM node:16-alpine AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app

# Install dependencies based on the preferred package manager
COPY package.json ./
RUN npm install


# Rebuild the source code only when needed
FROM node:16-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry during the build.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN npm run build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM node:16-alpine AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
# ENV NEXT_TELEMETRY_DISABLED 1

RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000

CMD ["node", "server.js"]

0 comments on commit 3ec2b26

Please sign in to comment.