Commit f69d63c4 authored by tom's avatar tom

deploy refactoring

parent daf2b2c8
...@@ -13,6 +13,7 @@ FROM node:16-alpine AS builder ...@@ -13,6 +13,7 @@ FROM node:16-alpine AS builder
WORKDIR /app WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules COPY --from=deps /app/node_modules ./node_modules
COPY . . COPY . .
COPY .env.template .env.production
# Next.js collects completely anonymous telemetry data about general usage. # Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry # Learn more here: https://nextjs.org/telemetry
...@@ -41,9 +42,10 @@ COPY --from=builder /app/next.config.js ./ ...@@ -41,9 +42,10 @@ COPY --from=builder /app/next.config.js ./
COPY --from=builder /app/public ./public COPY --from=builder /app/public ./public
COPY --from=builder /app/package.json ./package.json COPY --from=builder /app/package.json ./package.json
# Copy script and ENV templates file # Copy scripts and ENV templates file
COPY entrypoint.sh . COPY ./deploy/scripts/entrypoint.sh .
COPY .env.production . COPY ./deploy/scripts/replace_envs.sh .
COPY .env.template .
# Automatically leverage output traces to reduce image size # Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing # https://nextjs.org/docs/advanced-features/output-file-tracing
...@@ -53,6 +55,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static ...@@ -53,6 +55,8 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
# Execute script for replace build ENV with run ones # Execute script for replace build ENV with run ones
RUN apk add --no-cache --upgrade bash RUN apk add --no-cache --upgrade bash
RUN ["chmod", "+x", "./entrypoint.sh"] RUN ["chmod", "+x", "./entrypoint.sh"]
RUN ["chmod", "+x", "./replace_envs.sh"]
ENTRYPOINT ["./entrypoint.sh"] ENTRYPOINT ["./entrypoint.sh"]
USER nextjs USER nextjs
......
#!/bin/bash
./replace_envs.sh
echo "starting Nextjs"
exec "$@"
\ No newline at end of file
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
set +x set +x
# config # config
envFilename='.env.production' envFilename='.env.template'
nextFolder='./.next/' nextFolder='./.next/'
# replacing build-stage ENVs with run-stage ENVs # replacing build-stage ENVs with run-stage ENVs
# https://raphaelpralat.medium.com/system-environment-variables-in-next-js-with-docker-1f0754e04cde # https://raphaelpralat.medium.com/system-environment-variables-in-next-js-with-docker-1f0754e04cde
function apply_path { function replace_envs {
# read all config file # read all config file
while read line; do while read line; do
# no comment or not empty # no comment or not empty
...@@ -31,7 +31,4 @@ function apply_path { ...@@ -31,7 +31,4 @@ function apply_path {
done < $envFilename done < $envFilename
} }
apply_path replace_envs
\ No newline at end of file
echo "Starting Nextjs"
exec "$@"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment