-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build separate images for dev and prod
- Loading branch information
Showing
17 changed files
with
93 additions
and
281 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,30 +1,38 @@ | ||
# -|---------------------------------------------------------------------------- | ||
# | Intermediate image for building the application. | ||
# | Development image | ||
# -|---------------------------------------------------------------------------- | ||
FROM node:20-alpine AS builder | ||
FROM node:20-alpine AS dev | ||
WORKDIR /app | ||
ENV NODE_ENV=development | ||
|
||
COPY package.json package-lock.json ./ | ||
RUN npm ci | ||
|
||
COPY tsconfig.json ./ | ||
COPY src ./src | ||
RUN npm run build | ||
COPY public ./public | ||
|
||
ENV APP_KEYS="development - don't care" | ||
ENV JWT_SECRET="development - don't care" | ||
ENV ADMIN_JWT_SECRET="development - don't care" | ||
ENV API_TOKEN_SALT="development - don't care" | ||
|
||
ENTRYPOINT [ "npm", "run", "develop" ] | ||
|
||
# -|---------------------------------------------------------------------------- | ||
# | Final image containing only the files required to run in production. | ||
# | Production base image | ||
# -|---------------------------------------------------------------------------- | ||
FROM node:20-alpine AS production | ||
FROM node:20-alpine AS prod | ||
WORKDIR /app | ||
ENV NODE_ENV=production | ||
|
||
RUN apk add --no-cache vips-dev | ||
|
||
WORKDIR /app | ||
RUN chown node:node /app | ||
USER node | ||
ENV NODE_ENV=production | ||
|
||
COPY --from=builder --chown=node:node /app/package.json . | ||
COPY --from=builder --chown=node:node /app/dist dist | ||
COPY --from=builder --chown=node:node /app/node_modules node_modules | ||
COPY --chown=node:node public ./public | ||
COPY --from=dev --chown=node:node /app . | ||
COPY --chown=node:node server.js ./ | ||
|
||
EXPOSE 1337 | ||
ENTRYPOINT [ "npm", "run", "start" ] | ||
ENTRYPOINT [ "node", "server.js" ] |
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,61 +1,55 @@ | ||
# SehrGuteSoftware - Strapi Dockerized | ||
|
||
### Configuration | ||
|
||
The configuration is done via environment variables. The following variables are available: | ||
|
||
```bash | ||
# Server | ||
HOST=0.0.0.0 | ||
PORT=1337 | ||
APP_KEYS="toBeModified1,toBeModified2" | ||
API_TOKEN_SALT=tobemodified | ||
ADMIN_JWT_SECRET=tobemodified | ||
TRANSFER_TOKEN_SALT=tobemodified | ||
JWT_SECRET=tobemodified | ||
|
||
# Database | ||
DATABASE_CLIENT=postgres | ||
DATABASE_HOST=127.0.0.1 | ||
DATABASE_PORT=5432 | ||
DATABASE_NAME=strapi | ||
DATABASE_USERNAME=strapi | ||
DATABASE_PASSWORD=strapi | ||
DATABASE_SSL=false | ||
``` | ||
# Strapi Dockerized | ||
|
||
This repository provides development and production images for Strapi. | ||
|
||
## Development | ||
|
||
### Use in Docker Compose | ||
The development image can be used as-is, for example in a `compose.yaml`. The `src`, `config` and `public` directories from the source folder of your Strapi project must be mounted into the container. | ||
|
||
```yaml | ||
version: "3" | ||
services: | ||
postgres: | ||
image: postgres:16-alpine | ||
env_file: .env | ||
volumes: | ||
- ./postgres/data:/var/lib/postgresql/data | ||
- postgres-data:/var/lib/postgresql/data | ||
ports: | ||
- "5432:5432" | ||
environment: | ||
POSTGRES_DB: ${DATABASE_NAME} | ||
POSTGRES_USER: ${DATABASE_USERNAME} | ||
POSTGRES_PASSWORD: ${DATABASE_PASSWORD} | ||
POSTGRES_DB: strapi | ||
POSTGRES_USER: strapi | ||
POSTGRES_PASSWORD: strapi | ||
PGDATA: /var/lib/postgresql/data/pgdata | ||
strapi: | ||
image: strapi-test:latest | ||
env_file: .env | ||
# Uncomment the following line to use the development environment | ||
# environment: | ||
# NODE_ENV: development | ||
# command: ["npm", "run", "develop"] | ||
volumes: | ||
# - ./strapi/config:/opt/app/config # Before you use this, you need to copy the default `config` folder from github.com/sehrgutesoftware/strapi-dockerized | ||
- ./strapi/api:/opt/app/src/api | ||
- ./strapi/components:/opt/app/src/components | ||
- ./.env:/opt/app/.env | ||
image: ghcr.io/sehrgutesoftware/strapi-dockerized/dev:latest | ||
ports: | ||
- "1337:1337" | ||
environment: | ||
DATABASE_CLIENT: postgres | ||
DATABASE_HOST: postgres | ||
DATABASE_PORT: 5432 | ||
DATABASE_NAME: strapi | ||
DATABASE_USERNAME: strapi | ||
DATABASE_PASSWORD: strapi | ||
# See https://docs.strapi.io/dev-docs/configurations/environment for all environment variables | ||
volumes: | ||
- ${PWD}/src:/app/src | ||
- ${PWD}/config:/app/config | ||
- ${PWD}/public:/app/public | ||
depends_on: | ||
- postgres | ||
volumes: | ||
postgres-data: | ||
``` | ||
## Production | ||
The production image serves as a base image, which can be used in a Dockerfile to build an application-specific production docker image: | ||
```Dockerfile | ||
FROM ghcr.io/sehrgutesoftware/strapi-dockerized/prod:4.22.0 | ||
COPY --chown=node:node . . | ||
RUN npm run build | ||
``` | ||
|
||
Note that by default the `NODE_ENV` is set to `production`. If you want to use the development environment, you can uncomment the `environment` and `command` lines. | ||
Configuration values must be injected at run time via environment variables or a .env file. |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
const strapi = require("@strapi/strapi"); | ||
const app = strapi({ distDir: "./dist" }); | ||
app.start(); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.