Hello. I am trying to deploy Strapi to both a staging and production environment. I am using Docker to build the application and Docker stack to deploy it. I understand that environment variables are only set at build time. Does this mean I will need to build a separate docker image for both environments? And if so would my pipeline look like this:
- build staging (triggered on commit)
- deploy staging (triggered on commit)
- build prod (manual)
- deploy prod (manual)
Is there any way to improve this workflow?
My Dockerfile currently looks like this:
FROM strapi/base:12-alpine
ARG NODE_ENV
WORKDIR /src/app
COPY ./backend ./
RUN yarn
ENV NODE_ENV $NODE_ENV
RUN yarn build
# Re-add modules only for production
RUN rm -rf node_modules
RUN yarn --production
EXPOSE 1337
CMD [ "yarn", "start" ]
My docker-stack file looks like this:
version: '3.7'
services:
lessonplanner:
image: registry.gitlab.com/swaminarayan/lesson-planner/app:${DOCKER_TAG}
environment:
DATABASE_CLIENT: mysql
DATABASE_HOST: ${DB_HOST}
DATABASE_PORT: 3306
DATABASE_NAME: ${DB_NAME}
DATABASE_USERNAME: ${DB_USERNAME}
DATABASE_PASSWORD: ${DB_PASSWORD}
DATABASE_SSL: 'false'
PUBLIC_URL: ${PUBLIC_URL}
NODE_ENV: ${NODE_ENV}
networks:
- traefik-public
deploy:
restart_policy:
condition: on-failure
placement:
constraints:
- node.role==worker
- node.platform.os==linux
- node.labels.role==web
- node.labels.env==prod
labels:
- "traefik.enable=true"
- "traefik.http.routers.lessonplanner_http.middlewares=https_redirect@docker"
- "traefik.http.routers.lessonplanner_http.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.lessonplanner_http.entrypoints=http"
# https lb settings
- "traefik.http.routers.lessonplanner_https.rule=Host(`${DOMAIN}`)"
- "traefik.http.routers.lessonplanner_https.tls.certresolver=letsencrypt"
- "traefik.http.routers.lessonplanner_https.tls=true"
- "traefik.http.routers.lessonplanner_https.entrypoints=https"
- "traefik.http.routers.lessonplanner_https.service=lessonplanner_svc"
- "traefik.http.services.lessonplanner_svc.loadbalancer.server.port=1337"
networks:
traefik-public:
external: true
volumes:
lessonplanner-storage-app:
driver_opts:
type: "nfs"
o: "addr=10.16.103.88,nolock,soft,rw"
device: ":/zpool-124541/webstore/containers/lessonplanner/app"
Thanks in advance.