build: setup docker compose

This commit is contained in:
Reinaldy Rafli 2021-07-16 02:21:22 +07:00
parent 7714fa4139
commit 68f9cb5509
9 changed files with 168 additions and 1 deletions

7
api/.env.example Normal file
View File

@ -0,0 +1,7 @@
ENV=development
PORT=5000
DATABASE_URL=postgres://postgres:password@localhost:5432/jokesbapak2
REDIS_URL=redis://@localhost:6379
SENTRY_DSN=

4
api/.gitignore vendored
View File

@ -18,4 +18,6 @@ vendor/
.env .env
# Heroku bin directory # Heroku bin directory
bin bin
main

View File

@ -7,4 +7,6 @@ COPY . .
RUN go mod download RUN go mod download
RUN go build -v main.go RUN go build -v main.go
EXPOSE ${PORT}
CMD ["./main"] CMD ["./main"]

View File

@ -8,4 +8,6 @@ RUN npm install -g yarn
RUN yarn install RUN yarn install
RUN yarn build RUN yarn build
EXPOSE ${PORT}
CMD ["yarn", "preview"] CMD ["yarn", "preview"]

5
database/postgres/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
data
.crt
.key
.cnf
.dh

View File

@ -0,0 +1,13 @@
FROM postgres:13.3-alpine
WORKDIR /var/lib/postgresql
COPY . .
RUN apk add openssl
RUN chmod +x self-signed-ssl
RUN ./self-signed-ssl
RUN chown postgres /var/lib/postgresql/server.key && \
chmod 600 /var/lib/postgresql/server.key

View File

@ -0,0 +1,58 @@
#!/bin/bash
# COPIED/MODIFIED from the postgres server gen-certs util
# Generate some test certificates which are used by the regression test suite:
#
# tls/ca.{crt,key} Self signed CA certificate.
# tls/postgres.{crt,key} A certificate with no key usage/policy restrictions.
# tls/client.{crt,key} A certificate restricted for SSL client usage.
# tls/server.{crt,key} A certificate restricted for SSL server usage.
# tls/postgres.dh DH Params file.
generate_cert() {
local name=$1
local cn="$2"
local opts="$3"
local keyfile=${name}.key
local certfile=${name}.crt
[ -f $keyfile ] || openssl genrsa -out $keyfile 2048
openssl req \
-new -sha256 \
-subj "/O=postgres Test/CN=$cn" \
-key $keyfile | \
openssl x509 \
-req -sha256 \
-CA ca.crt \
-CAkey ca.key \
-CAserial ca.txt \
-CAcreateserial \
-days 365 \
$opts \
-out $certfile
}
[ -f ca.key ] || openssl genrsa -out ca.key 4096
openssl req \
-x509 -new -nodes -sha256 \
-key ca.key \
-days 3650 \
-subj '/O=postgres Test/CN=Certificate Authority' \
-out ca.crt
cat > openssl.cnf <<_END_
[ server_cert ]
keyUsage = digitalSignature, keyEncipherment
nsCertType = server
[ client_cert ]
keyUsage = digitalSignature, keyEncipherment
nsCertType = client
_END_
generate_cert server "Server-only" "-extfile openssl.cnf -extensions server_cert"
generate_cert client "Client-only" "-extfile openssl.cnf -extensions client_cert"
generate_cert postgres "Generic-cert"
[ -f postgres.dh ] || openssl dhparam -out postgres.dh 2048

2
database/redis/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
data
etc

76
docker-compose.yml Normal file
View File

@ -0,0 +1,76 @@
services:
api:
build: ./api/
restart: always
env_file: ./api/.env
ports:
- 5000:5000
depends_on:
- db
- cache
# Uncomment these if you want to have it on
# volumes:
# ./api:/app
client:
build: ./client/
restart: always
env_file: ./client/.env
ports:
- 3000:3000
depends_on:
- api
# Uncomment these if you want to have it on
# volumes:
# ./client:/app
db:
build: ./database/postgres/
command: >
-c ssl=on
-c ssl_cert_file=/var/lib/postgresql/server.crt
-c ssl_key_file=/var/lib/postgresql/server.key
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: jokesbapak2
PGDATA: /data/postgres
# I got this key from somewhere. It works when you run it locally.
POSTGRES_SSL_CA_CERT: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSURjekNDQWx1Z0F3SUJBZ0lVR3lDaElvR3g0
volumes:
- ./database/postgres/data:/data/postgres
cache:
image: redis:6.2.4-alpine
restart: always
ports:
- 6379:6379
volumes:
- ./database/redis/etc:/usr/local/etc/redis
- ./database/redis/data:/data
cache-admin:
image: rediscommander/redis-commander:latest
restart: always
environment:
REDIS_PORT: 6379
REDIS_HOST: redis
ports:
- 2084:8081
depends_on:
- cache
db-admin:
image: sosedoff/pgweb:0.11.8
restart: always
ports:
- 2086:8081
links:
- postgres:postgres
environment:
DATABASE_URL: postgres://postgres:password@db/jokesbapak2
depends_on:
- db