Skip to content

Instantly share code, notes, and snippets.

@dsalahutdinov
Created April 14, 2019 07:25
Show Gist options
  • Save dsalahutdinov/47487f319eeaa12cb2026daf9c06f8f0 to your computer and use it in GitHub Desktop.
Save dsalahutdinov/47487f319eeaa12cb2026daf9c06f8f0 to your computer and use it in GitHub Desktop.
Dockerize Golang backend
version: '3'
services:
app: &app
image: ampgs:0.3.1-development
build:
context: .
dockerfile: docker/development/Dockerfile
env_file:
- .env
environment:
PORT: 8000
PROMETHEUS_PORT: 2121
REDIS_URL: redis://redis:6379/6
DATABASE_URL: postgres://postgres:postgres@postgres:5432/ampgs?sslmode=disable
volumes:
- .:/go/src/github.com/evilmartians/ampgs
depends_on:
- redis
- postgres
runner:
<<: *app
test:
<<: *app
command: "go test -v ./..."
web:
<<: *app
command: make web
ports:
- '8000:8000'
- '2121:2121'
networks:
default:
amplifr_internal:
aliases:
- ampgs-server
redis:
image: redis:4-alpine
volumes:
- redis:/data
ports:
- 6379
postgres:
image: postgres:9.6-alpine
environment:
POSTGRES_DB: ampgs
volumes:
- postgres:/var/lib/postgresql/data
ports:
- 5432
volumes:
redis:
postgres:
networks:
amplifr_internal:
external: true
FROM golang:1.11
ARG MIGRATE_VERSION=4.0.2
# install postgres client for local development
RUN apt-get update && apt-get install -y postgresql-client
# install dep tool to ensuring dependencies
RUN go get -u github.com/golang/dep/cmd/dep
# install migrate cli for running database migrations
ADD https://github.com/golang-migrate/migrate/releases/download/v${MIGRATE_VERSION}/migrate.linux-amd64.tar.gz /tmp
RUN tar -xzf /tmp/migrate.linux-amd64.tar.gz -C /usr/local/bin && mv /usr/local/bin/migrate.linux-amd64 /usr/local/bin/migrate
ENV APP ${GOPATH}/src/github.com/evilmartians/ampgs
WORKDIR ${APP}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment