Add docker-compose for production use

This commit is contained in:
Grégoire Delattre 2017-02-02 16:26:58 +01:00 committed by Lucas BEE
parent c386f12613
commit d57f119c7a
4 changed files with 56 additions and 4 deletions

View File

@ -27,8 +27,11 @@ docker:
build_docker_image:
rm -rf canapeapp
mkdir canapeapp
cp -R docker/run.sh canapeapp/run.sh
cp -R sql/migration canapeapp/migrations
cp $$GOPATH/bin/migrate canapeapp/migrate
yarn build
CGO_ENABLED=0 go build -v -o canapeapp/app src/main.go
go build -v -o canapeapp/app src/main.go
docker build --tag canapeapp:latest --file docker/Dockerfile-production .
rm -rf canapeapp

View File

@ -1,6 +1,5 @@
FROM alpine:3.5
FROM debian:8.7
COPY canapeapp /opt/canapeapp
WORKDIR /opt/canapeapp
RUN chmod +x /opt/canapeapp
CMD ["/opt/canapeapp"]
CMD ["/opt/canapeapp/run.sh"]

View File

@ -0,0 +1,40 @@
version: "3"
networks:
canapeapp:
external: false
services:
database:
image: postgres:9.5
container_name: canapeapp_database
restart: always
environment:
- POSTGRES_PASSWORD=test
- POSTGRES_USER=test
- POSTGRES_DB=production
networks:
- canapeapp
# volumes:
# - .:/docker-entrypoint-initdb.d/
ports:
- 5432
app:
image: canapeapp:latest
container_name: canapeapp
restart: always
depends_on:
- database
environment:
- CONFIG_FILE=/etc/canapeapp.yml
- DB_USER=test
- DB_PASS=test
- DB_ENV=production
networks:
- canapeapp
ports:
- 127.0.0.1:6666:3000
volumes:
- ../config-prod.yml:/etc/canapeapp.yml:ro
links:
- database

10
docker/run.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
echo "Running migrations..."
/opt/canapeapp/migrate \
-url postgres://${DB_USER}:${DB_PASS}@database:5432/${DB_ENV}?sslmode=disable \
-path /opt/canapeapp/migrations \
up
echo "Migrations done"
exec /opt/canapeapp/app