Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker-compose for development environment #76

Merged
merged 12 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,22 @@ This repository contains 3 separate apps:

1. Change directory to `publish-backend` directory

1. Create a copy of the `.env.example` file and name it `.env`. Add required
values.
2. Create a copy of the `.env.example` file and name it `.env`

1. Run `npm install`
raisedadead marked this conversation as resolved.
Show resolved Hide resolved
3. Run `npm install`

1. Run `npm run cs import` to import config from `config/sync/*` files into
database
4. Run `docker compose up`

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

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

1. You will be prompted to create an Admin account if there is no account in
your local environment yet.
7. You will be prompted to create an Admin account if there is no account in
your local environment yet. Create an account here.

Note: This is an account to login to the admin panel. It's different from the
account to login to the frontend app.

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

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

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

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

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

### publish-backend (Strapi)

- The Admin panel will be for developers only. Contributors will write articles
on `publish-frontend` (Next.js) app.

- You need to run the Strapi app in development mode to modify any Content-Type
(data structure). If you use `docker compose up` it's configured to do so.

- 💡 If you change configurations from the Admin panel, make sure to export
those config by running `npm run cs export`. This command will generate files
under `config/sync` directory. Include those files in your Git commit. For
Expand Down
11 changes: 8 additions & 3 deletions publish-backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ ADMIN_JWT_SECRET=tobemodified
TRANSFER_TOKEN_SALT=tobemodified
JWT_SECRET=tobemodified

# Database
DATABASE_CLIENT=sqlite
DATABASE_FILENAME=.tmp/data.db
# Database (Postgres)
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=strapi
DATABASE_USERNAME=strapi
DATABASE_PASSWORD=password
NODE_ENV=development
DATABASE_CLIENT=postgres

# i18n
STRAPI_PLUGIN_I18N_INIT_LOCALE_CODE=en
5 changes: 5 additions & 0 deletions publish-backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ dist
build
.strapi-updater.json

############################
# Docker
############################
data

############################
# VS Code
############################
Expand Down
103 changes: 56 additions & 47 deletions publish-backend/config/database.js
Original file line number Diff line number Diff line change
@@ -1,81 +1,90 @@
const path = require('path');
const path = require("path");

module.exports = ({ env }) => {
const client = env('DATABASE_CLIENT', 'sqlite');
const client = env("DATABASE_CLIENT", "sqlite");

const connections = {
mysql: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
connectionString: env("DATABASE_URL"),
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 3306),
database: env("DATABASE_NAME", "strapi"),
user: env("DATABASE_USERNAME", "strapi"),
password: env("DATABASE_PASSWORD", "strapi"),
ssl: env.bool("DATABASE_SSL", false) && {
key: env("DATABASE_SSL_KEY", undefined),
cert: env("DATABASE_SSL_CERT", undefined),
ca: env("DATABASE_SSL_CA", undefined),
capath: env("DATABASE_SSL_CAPATH", undefined),
cipher: env("DATABASE_SSL_CIPHER", undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
"DATABASE_SSL_REJECT_UNAUTHORIZED",
true
),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
pool: {
min: env.int("DATABASE_POOL_MIN", 2),
max: env.int("DATABASE_POOL_MAX", 10),
},
},
mysql2: {
connection: {
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 3306),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 3306),
database: env("DATABASE_NAME", "strapi"),
user: env("DATABASE_USERNAME", "strapi"),
password: env("DATABASE_PASSWORD", "strapi"),
ssl: env.bool("DATABASE_SSL", false) && {
key: env("DATABASE_SSL_KEY", undefined),
cert: env("DATABASE_SSL_CERT", undefined),
ca: env("DATABASE_SSL_CA", undefined),
capath: env("DATABASE_SSL_CAPATH", undefined),
cipher: env("DATABASE_SSL_CIPHER", undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
"DATABASE_SSL_REJECT_UNAUTHORIZED",
true
),
},
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
pool: {
min: env.int("DATABASE_POOL_MIN", 2),
max: env.int("DATABASE_POOL_MAX", 10),
},
},
postgres: {
connection: {
connectionString: env('DATABASE_URL'),
host: env('DATABASE_HOST', 'localhost'),
port: env.int('DATABASE_PORT', 5432),
database: env('DATABASE_NAME', 'strapi'),
user: env('DATABASE_USERNAME', 'strapi'),
password: env('DATABASE_PASSWORD', 'strapi'),
ssl: env.bool('DATABASE_SSL', false) && {
key: env('DATABASE_SSL_KEY', undefined),
cert: env('DATABASE_SSL_CERT', undefined),
ca: env('DATABASE_SSL_CA', undefined),
capath: env('DATABASE_SSL_CAPATH', undefined),
cipher: env('DATABASE_SSL_CIPHER', undefined),
connectionString: env("DATABASE_URL"),
host: env("DATABASE_HOST", "localhost"),
port: env.int("DATABASE_PORT", 5432),
database: env("DATABASE_NAME", "strapi"),
user: env("DATABASE_USERNAME", "strapi"),
password: env("DATABASE_PASSWORD", "strapi"),
ssl: env.bool("DATABASE_SSL", false) && {
key: env("DATABASE_SSL_KEY", undefined),
cert: env("DATABASE_SSL_CERT", undefined),
ca: env("DATABASE_SSL_CA", undefined),
capath: env("DATABASE_SSL_CAPATH", undefined),
cipher: env("DATABASE_SSL_CIPHER", undefined),
rejectUnauthorized: env.bool(
'DATABASE_SSL_REJECT_UNAUTHORIZED',
"DATABASE_SSL_REJECT_UNAUTHORIZED",
true
),
},
schema: env('DATABASE_SCHEMA', 'public'),
schema: env("DATABASE_SCHEMA", "public"),
},
pool: {
min: env.int("DATABASE_POOL_MIN", 2),
max: env.int("DATABASE_POOL_MAX", 10),
},
pool: { min: env.int('DATABASE_POOL_MIN', 2), max: env.int('DATABASE_POOL_MAX', 10) },
},
sqlite: {
connection: {
filename: path.join(
__dirname,
'..',
env('DATABASE_FILENAME', 'data.db')
"..",
env("DATABASE_FILENAME", "data.db")
),
},
useNullAsDefault: true,
Expand All @@ -86,7 +95,7 @@ module.exports = ({ env }) => {
connection: {
client,
...connections[client],
acquireConnectionTimeout: env.int('DATABASE_CONNECTION_TIMEOUT', 60000),
acquireConnectionTimeout: env.int("DATABASE_CONNECTION_TIMEOUT", 60000),
},
};
};
59 changes: 59 additions & 0 deletions publish-backend/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
version: "3"
services:
strapi:
container_name: strapi
build: .
image: strapi:latest
restart: unless-stopped
env_file: .env
environment:
DATABASE_CLIENT: ${DATABASE_CLIENT}
DATABASE_HOST: strapiDB
DATABASE_PORT: ${DATABASE_PORT}
DATABASE_NAME: ${DATABASE_NAME}
DATABASE_USERNAME: ${DATABASE_USERNAME}
DATABASE_PASSWORD: ${DATABASE_PASSWORD}
JWT_SECRET: ${JWT_SECRET}
ADMIN_JWT_SECRET: ${ADMIN_JWT_SECRET}
APP_KEYS: ${APP_KEYS}
NODE_ENV: ${NODE_ENV}
volumes:
- ./config:/opt/app/config
- ./src:/opt/app/src
- ./package.json:/opt/package.json
- ./package-lock.json:/opt/package-lock.json
- ./.env:/opt/app/.env
- ./public/uploads:/opt/app/public/uploads
ports:
- "1337:1337"
networks:
- strapi
depends_on:
- strapiDB

strapiDB:
container_name: strapiDB
platform: linux/amd64 #for platform error on Apple M1 chips
restart: unless-stopped
env_file: .env
image: postgres:14-alpine
environment:
POSTGRES_USER: ${DATABASE_USERNAME}
POSTGRES_PASSWORD: ${DATABASE_PASSWORD}
POSTGRES_DB: ${DATABASE_NAME}
volumes:
- strapi-data:/var/lib/postgresql/data/ #using a volume
# - ./data:/var/lib/postgresql/data/ # if you want to use a bind folder

ports:
- "5432:5432"
networks:
- strapi

volumes:
strapi-data:

networks:
strapi:
name: Strapi
driver: bridge
Loading