Skip to content

Commit

Permalink
feat: dockerize run environment
Browse files Browse the repository at this point in the history
  • Loading branch information
romeq committed Feb 13, 2023
1 parent 2aaa4d9 commit 81b3f68
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 21 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM golang:1.20-alpine3.17

WORKDIR /app

COPY go.mod go.sum ./
RUN go mod download && go mod verify

COPY . .

EXPOSE 8080

RUN apk update && apk add postgresql-client make

CMD ["make", "migrate", "run"]
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#general
GO=/bin/env go
CGO_ENABLED ?= 1
GO=go

#database
DB_USERNAME ?= pac
Expand All @@ -11,22 +12,24 @@ PG_STRING ?= postgres://$(DB_USERNAME):$(DB_PASSWORD)@$(DB_HOST):$(DB_PORT)/$(DB

#paths
SERVER_PKG=./cmd/server

up: run
SERVER_BIN=./server-bin

migrate:
@-cat ./sqlc/models/* | psql -d $(PG_STRING) >/dev/null

migrate-down:
@-psql -d $(PG_STRING) -f ./sqlc/down.sql >/dev/null

psql:
db-shell:
@-psql -qd $(PG_STRING)

clean-db: migrate-down migrate

run:
@$(GO) run $(SERVER_PKG)
db-reset: migrate-down migrate

build:
@$(GO) build -o server-binary $(SERVER_PKG)
@-CGO_ENABLED=$(CGO_ENABLED) $(GO) build -o $(SERVER_BIN) $(SERVER_PKG)

run: build
@-$(SERVER_BIN)

clean:
rm $(SERVER_BIN)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ I don't know why you would want to setup this, but oh boy it's easy (I'm just ex
git clone [email protected]:romeq/pac.git
# or alternatively via http:
# git clone https://github.com/romeq/pac.git
docker-compose up -d
make clean-db run
docker-compose up
```


Expand Down
31 changes: 21 additions & 10 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
version: '3.8'
version: '3.9'

services:
postgres:
image: 'postgres'
database:
image: "postgres:15.1-alpine"
restart: unless-stopped

environment:
POSTGRES_USER: ${DB_USERNAME:-pac}
POSTGRES_PASSWORD: ${DB_PASSWORD:-pac}
ports:
- "${DB_PORT:-5432}:5432"
expose:
- "${DB_PORT:-5432}"
POSTGRES_USER: pac
POSTGRES_PASSWORD: pac

volumes:
- "${DB_STORAGE_LOCATION:-./cache/postgres}:/var/lib/postgresql/data:rw"
- "${DB_STORAGE:-./dbstorage}:/var/lib/postgresql/data:rw"

server:
build:
dockerfile: Dockerfile
context: .
restart: always
depends_on:
- database
environment:
DB_USERNAME: pac
DB_PASSWORD: pac
DB_HOST: database

0 comments on commit 81b3f68

Please sign in to comment.