Skip to content

Commit

Permalink
build(docker): add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
danvergara committed May 1, 2021
1 parent 58d4ae8 commit 6bf535d
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
FROM golang:1.16-buster AS builder

WORKDIR /src/app

# install system dependencies
RUN apt-get update \
&& apt-get -y install netcat \
&& apt-get clean

COPY go.* ./
RUN go mod download
COPY . .

ARG TARGETOS
ARG TARGETARCH

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o dblab .

FROM scratch AS bin

LABEL org.opencontainers.image.documentation="https://github.com/danvergara/dblab" \
org.opencontainers.image.source="https://github.com/danvergara/dblab" \
org.opencontainers.image.title="dblab"

COPY --from=builder /src/app/dblab /bin/dblab
33 changes: 33 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.9"

services:
postgres:
image: postgres:12.1-alpine
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- POSTGRES_DB=users
ports:
- '5432:5432'
networks:
- dblab

dblab:
build:
context: .
target: builder
depends_on:
- postgres
environment:
- DB_HOST=postgres
- DB_USER=postgres
- DB_PASSWORD=password
- DB_NAME=users
- DB_PORT=5432
- DB_DRIVER=postgres
entrypoint: ["/bin/bash", "./scripts/entripoint.dev.sh"]
networks:
- dblab

networks:
dblab:
17 changes: 17 additions & 0 deletions scripts/entripoint.dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

echo "Waiting for postgres..."

while ! nc -z postgres 5432; do
sleep 0.1
done

echo "PostgreSQL started"

echo "Runinng the migrations against the DB"
go run cmd/dbmigrate/main.go

echo "Seeding the database"
go run cmd/seeder/main.go seed

0 comments on commit 6bf535d

Please sign in to comment.