-
Notifications
You must be signed in to change notification settings - Fork 492
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: moving blog from swa to container apps
- Loading branch information
1 parent
eb7863c
commit 3ec2b26
Showing
5 changed files
with
116 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,4 @@ services: | |
|
||
blog: | ||
project: packages/blog | ||
language: ts | ||
host: staticwebapp | ||
dist: . | ||
host: containerapp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |