Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit bf52eef

Browse files
authored
Add docker-compose for development environment (#76)
1 parent 8fb44fc commit bf52eef

File tree

9 files changed

+296
-74
lines changed

9 files changed

+296
-74
lines changed

docs/README.md

+25-22
Original file line numberDiff line numberDiff line change
@@ -28,24 +28,22 @@ This repository contains 3 separate apps:
2828

2929
1. Change directory to `publish-backend` directory
3030

31-
1. Create a copy of the `.env.example` file and name it `.env`. Add required
32-
values.
31+
2. Create a copy of the `.env.example` file and name it `.env`
3332

34-
1. Run `npm install`
33+
3. Run `npm install`
3534

36-
1. Run `npm run cs import` to import config from `config/sync/*` files into
37-
database
35+
4. Run `docker compose up`
3836

39-
1. Run `npm run develop` to start the Strapi app in development mode
40-
Note: You need to run the Strapi app in development mode to modify any
41-
Content-Type (data structure).
37+
5. In another terminal, go to `publish-backend` and run `npm run cs import`.
38+
This will import config from `config/sync/*` files into the database.
4239

43-
1. Visit http://localhost:1337/admin to access the admin panel.
44-
Note: This will be the Admin panel for developers/staff. Contributors will
45-
write articles on `publish-frontend` (Next.js) app.
40+
6. Visit http://localhost:1337/admin to access the admin panel
4641

47-
1. You will be prompted to create an Admin account if there is no account in
48-
your local environment yet.
42+
7. You will be prompted to create an Admin account if there is no account in
43+
your local environment yet. Create an account here.
44+
45+
Note: This is an account to login to the admin panel. It's different from the
46+
account to login to the frontend app.
4947

5048
1. Under `General > Settings > Users & Permissions Plugin > Providers`, enable
5149
`Google` and `Local` providers. Follow this [link](
@@ -58,21 +56,20 @@ This repository contains 3 separate apps:
5856
### Run publish-frontend (Next.js) app
5957

6058
1. In another terminal, go to `publish-frontend` directory
61-
1. Create a copy of the `sample.env.local` file and name it `.env.local`. Add
62-
required values. Use the same Google OAuth credentials as you used for
63-
`publish-backend` (Strapi) app.
64-
1. Run `npm install`
65-
1. Make sure the backend Strapi app is running in another terminal. Then start
59+
2. Create a copy of the `sample.env.local` file and name it `.env.local`. Add
60+
required values.
61+
3. Run `npm install`
62+
4. Make sure the backend Strapi app is running in another terminal. Then start
6663
the frontend Next.js app by running `npm run dev`.
67-
1. Visit http://localhost:3000/ to access the authoring site
64+
5. Visit http://localhost:3000/ to access the authoring site
6865

6966
### Run publish-11ty-test (11ty) app
7067

7168
1. In another terminal, go to `publish-11ty-test` directory
72-
1. Run `yarn install`
73-
1. Make sure the backend Strapi app is running in another terminal. Then run
69+
2. Run `yarn install`
70+
3. Make sure the backend Strapi app is running in another terminal. Then run
7471
`yarn serve` to build the static site and serve it.
75-
1. Visit http://localhost:8080/ to see the user-facing site
72+
4. Visit http://localhost:8080/ to see the user-facing site
7673

7774
- If you made changes to the contents saved in the backend database, you will
7875
need to re-build the static site by running `yarn serve` again to see the
@@ -82,6 +79,12 @@ This repository contains 3 separate apps:
8279

8380
### publish-backend (Strapi)
8481

82+
- The Admin panel will be for developers only. Contributors will write articles
83+
on `publish-frontend` (Next.js) app.
84+
85+
- You need to run the Strapi app in development mode to modify any Content-Type
86+
(data structure). If you use `docker compose up` it's configured to do so.
87+
8588
- 💡 If you change configurations from the Admin panel, make sure to export
8689
those config by running `npm run cs export`. This command will generate files
8790
under `config/sync` directory. Include those files in your Git commit. For

publish-backend/.env.example

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ ADMIN_JWT_SECRET=tobemodified
66
TRANSFER_TOKEN_SALT=tobemodified
77
JWT_SECRET=tobemodified
88

9-
# Database
10-
DATABASE_CLIENT=sqlite
11-
DATABASE_FILENAME=.tmp/data.db
9+
# Database (Postgres)
10+
DATABASE_HOST=localhost
11+
DATABASE_PORT=5432
12+
DATABASE_NAME=strapi
13+
DATABASE_USERNAME=strapi
14+
DATABASE_PASSWORD=password
15+
NODE_ENV=development
16+
DATABASE_CLIENT=postgres
1217

1318
# i18n
1419
STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE=en

publish-backend/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ dist
114114
build
115115
.strapi-updater.json
116116

117+
############################
118+
# Docker
119+
############################
120+
data
121+
117122
############################
118123
# VS Code
119124
############################

publish-backend/config/database.js

+56-47
Original file line numberDiff line numberDiff line change
@@ -1,81 +1,90 @@
1-
const path = require('path');
1+
const path = require("path");
22

33
module.exports = ({ env }) => {
4-
const client = env('DATABASE_CLIENT', 'sqlite');
4+
const client = env("DATABASE_CLIENT", "sqlite");
55

66
const connections = {
77
mysql: {
88
connection: {
9-
connectionString: env('DATABASE_URL'),
10-
host: env('DATABASE_HOST', 'localhost'),
11-
port: env.int('DATABASE_PORT', 3306),
12-
database: env('DATABASE_NAME', 'strapi'),
13-
user: env('DATABASE_USERNAME', 'strapi'),
14-
password: env('DATABASE_PASSWORD', 'strapi'),
15-
ssl: env.bool('DATABASE_SSL', false) && {
16-
key: env('DATABASE_SSL_KEY', undefined),
17-
cert: env('DATABASE_SSL_CERT', undefined),
18-
ca: env('DATABASE_SSL_CA', undefined),
19-
capath: env('DATABASE_SSL_CAPATH', undefined),
20-
cipher: env('DATABASE_SSL_CIPHER', undefined),
9+
connectionString: env("DATABASE_URL"),
10+
host: env("DATABASE_HOST", "localhost"),
11+
port: env.int("DATABASE_PORT", 3306),
12+
database: env("DATABASE_NAME", "strapi"),
13+
user: env("DATABASE_USERNAME", "strapi"),
14+
password: env("DATABASE_PASSWORD", "strapi"),
15+
ssl: env.bool("DATABASE_SSL", false) && {
16+
key: env("DATABASE_SSL_KEY", undefined),
17+
cert: env("DATABASE_SSL_CERT", undefined),
18+
ca: env("DATABASE_SSL_CA", undefined),
19+
capath: env("DATABASE_SSL_CAPATH", undefined),
20+
cipher: env("DATABASE_SSL_CIPHER", undefined),
2121
rejectUnauthorized: env.bool(
22-
'DATABASE_SSL_REJECT_UNAUTHORIZED',
22+
"DATABASE_SSL_REJECT_UNAUTHORIZED",
2323
true
2424
),
2525
},
2626
},
27-
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
27+
pool: {
28+
min: env.int("DATABASE_POOL_MIN", 2),
29+
max: env.int("DATABASE_POOL_MAX", 10),
30+
},
2831
},
2932
mysql2: {
3033
connection: {
31-
host: env('DATABASE_HOST', 'localhost'),
32-
port: env.int('DATABASE_PORT', 3306),
33-
database: env('DATABASE_NAME', 'strapi'),
34-
user: env('DATABASE_USERNAME', 'strapi'),
35-
password: env('DATABASE_PASSWORD', 'strapi'),
36-
ssl: env.bool('DATABASE_SSL', false) && {
37-
key: env('DATABASE_SSL_KEY', undefined),
38-
cert: env('DATABASE_SSL_CERT', undefined),
39-
ca: env('DATABASE_SSL_CA', undefined),
40-
capath: env('DATABASE_SSL_CAPATH', undefined),
41-
cipher: env('DATABASE_SSL_CIPHER', undefined),
34+
host: env("DATABASE_HOST", "localhost"),
35+
port: env.int("DATABASE_PORT", 3306),
36+
database: env("DATABASE_NAME", "strapi"),
37+
user: env("DATABASE_USERNAME", "strapi"),
38+
password: env("DATABASE_PASSWORD", "strapi"),
39+
ssl: env.bool("DATABASE_SSL", false) && {
40+
key: env("DATABASE_SSL_KEY", undefined),
41+
cert: env("DATABASE_SSL_CERT", undefined),
42+
ca: env("DATABASE_SSL_CA", undefined),
43+
capath: env("DATABASE_SSL_CAPATH", undefined),
44+
cipher: env("DATABASE_SSL_CIPHER", undefined),
4245
rejectUnauthorized: env.bool(
43-
'DATABASE_SSL_REJECT_UNAUTHORIZED',
46+
"DATABASE_SSL_REJECT_UNAUTHORIZED",
4447
true
4548
),
4649
},
4750
},
48-
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
51+
pool: {
52+
min: env.int("DATABASE_POOL_MIN", 2),
53+
max: env.int("DATABASE_POOL_MAX", 10),
54+
},
4955
},
5056
postgres: {
5157
connection: {
52-
connectionString: env('DATABASE_URL'),
53-
host: env('DATABASE_HOST', 'localhost'),
54-
port: env.int('DATABASE_PORT', 5432),
55-
database: env('DATABASE_NAME', 'strapi'),
56-
user: env('DATABASE_USERNAME', 'strapi'),
57-
password: env('DATABASE_PASSWORD', 'strapi'),
58-
ssl: env.bool('DATABASE_SSL', false) && {
59-
key: env('DATABASE_SSL_KEY', undefined),
60-
cert: env('DATABASE_SSL_CERT', undefined),
61-
ca: env('DATABASE_SSL_CA', undefined),
62-
capath: env('DATABASE_SSL_CAPATH', undefined),
63-
cipher: env('DATABASE_SSL_CIPHER', undefined),
58+
connectionString: env("DATABASE_URL"),
59+
host: env("DATABASE_HOST", "localhost"),
60+
port: env.int("DATABASE_PORT", 5432),
61+
database: env("DATABASE_NAME", "strapi"),
62+
user: env("DATABASE_USERNAME", "strapi"),
63+
password: env("DATABASE_PASSWORD", "strapi"),
64+
ssl: env.bool("DATABASE_SSL", false) && {
65+
key: env("DATABASE_SSL_KEY", undefined),
66+
cert: env("DATABASE_SSL_CERT", undefined),
67+
ca: env("DATABASE_SSL_CA", undefined),
68+
capath: env("DATABASE_SSL_CAPATH", undefined),
69+
cipher: env("DATABASE_SSL_CIPHER", undefined),
6470
rejectUnauthorized: env.bool(
65-
'DATABASE_SSL_REJECT_UNAUTHORIZED',
71+
"DATABASE_SSL_REJECT_UNAUTHORIZED",
6672
true
6773
),
6874
},
69-
schema: env('DATABASE_SCHEMA', 'public'),
75+
schema: env("DATABASE_SCHEMA", "public"),
76+
},
77+
pool: {
78+
min: env.int("DATABASE_POOL_MIN", 2),
79+
max: env.int("DATABASE_POOL_MAX", 10),
7080
},
71-
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
7281
},
7382
sqlite: {
7483
connection: {
7584
filename: path.join(
7685
__dirname,
77-
'..',
78-
env('DATABASE_FILENAME', 'data.db')
86+
"..",
87+
env("DATABASE_FILENAME", "data.db")
7988
),
8089
},
8190
useNullAsDefault: true,
@@ -86,7 +95,7 @@ module.exports = ({ env }) => {
8695
connection: {
8796
client,
8897
...connections[client],
89-
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
98+
acquireConnectionTimeout: env.int("DATABASE_CONNECTION_TIMEOUT", 60000),
9099
},
91100
};
92101
};

publish-backend/docker-compose.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
version: "3"
2+
services:
3+
strapi:
4+
container_name: strapi
5+
build: .
6+
image: strapi:latest
7+
restart: unless-stopped
8+
env_file: .env
9+
environment:
10+
DATABASE_CLIENT: ${DATABASE_CLIENT}
11+
DATABASE_HOST: strapiDB
12+
DATABASE_PORT: ${DATABASE_PORT}
13+
DATABASE_NAME: ${DATABASE_NAME}
14+
DATABASE_USERNAME: ${DATABASE_USERNAME}
15+
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
16+
JWT_SECRET: ${JWT_SECRET}
17+
ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
18+
APP_KEYS: ${APP_KEYS}
19+
NODE_ENV: ${NODE_ENV}
20+
volumes:
21+
- ./config:/opt/app/config
22+
- ./src:/opt/app/src
23+
- ./package.json:/opt/package.json
24+
- ./package-lock.json:/opt/package-lock.json
25+
- ./.env:/opt/app/.env
26+
- ./public/uploads:/opt/app/public/uploads
27+
ports:
28+
- "1337:1337"
29+
networks:
30+
- strapi
31+
depends_on:
32+
- strapiDB
33+
34+
strapiDB:
35+
container_name: strapiDB
36+
platform: linux/amd64 #for platform error on Apple M1 chips
37+
restart: unless-stopped
38+
env_file: .env
39+
image: postgres:14-alpine
40+
environment:
41+
POSTGRES_USER: ${DATABASE_USERNAME}
42+
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
43+
POSTGRES_DB: ${DATABASE_NAME}
44+
volumes:
45+
- strapi-data:/var/lib/postgresql/data/ #using a volume
46+
# - ./data:/var/lib/postgresql/data/ # if you want to use a bind folder
47+
48+
ports:
49+
- "5432:5432"
50+
networks:
51+
- strapi
52+
53+
volumes:
54+
strapi-data:
55+
56+
networks:
57+
strapi:
58+
name: Strapi
59+
driver: bridge

0 commit comments

Comments
 (0)