Skip to content

Commit

Permalink
Add docker
Browse files Browse the repository at this point in the history
  • Loading branch information
bifidokk committed Apr 20, 2024
1 parent b09041b commit 184465b
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
COMPOSE_PROJECT_NAME=whisper-bot

POSTGRES_MIGRATION_DSN="postgres://postgres:postgres@postgres:5432/whisperbot?sslmode=disable"
16 changes: 16 additions & 0 deletions .docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.22 as builder

WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY . ./

RUN go build ./cmd/main.go

FROM alpine:latest
RUN apk add --no-cache ca-certificates libc6-compat

WORKDIR /app
COPY --from=builder /app .

CMD ["./main"]
10 changes: 10 additions & 0 deletions .docker/app/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.22

WORKDIR /app

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

RUN go build ./cmd/main.go

CMD ["./main"]
5 changes: 5 additions & 0 deletions .docker/bot_dev.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
APP_TOKEN=
APP_WEBHOOK_URL=
APP_WEBHOOK_PATH="/bot/"
APP_BASE_URL=":9000"
APP_OPENAI_TOKEN=
45 changes: 45 additions & 0 deletions .docker/docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
version: '3'

services:
postgres:
image: postgres:14.1
container_name: db
ports:
- "5432:5432"
restart: always
environment:
POSTGRES_PASSWORD: postgres
volumes:
- ./db/:/var/lib/postgresql/data/:rw
- ./postgres/init:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5

app:
container_name: app
build:
context: ../
dockerfile: ./.docker/app/Dockerfile.dev
ports:
- "8080:8080"
restart: always
depends_on:
postgres:
condition: service_healthy
env_file:
- bot_dev.env

migrations:
container_name: migrations
build:
context: ../
dockerfile: ./.docker/migrations/Dockerfile.dev
command: migrate apply --url ${POSTGRES_MIGRATION_DSN} --dir "file://migrations"
depends_on:
postgres:
condition: service_healthy
env_file:
- bot_dev.env
43 changes: 43 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
version: '3'

services:
postgres:
image: postgres:14.1
container_name: db
environment:
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
PGDATA: /var/lib/postgresql/data/
volumes:
- ./db:/var/lib/postgresql/data/:rw
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
interval: 5s
timeout: 5s
retries: 5
env_file:
- .env.prod

app:
container_name: app
image: bifidokk/whisper-bot-app:latest
ports:
- ${API_PORT}:8080
restart: always
depends_on:
postgres:
condition: service_healthy
env_file:
- .env.prod

migrations:
container_name: migrations
image: bifidokk/whisper-bot-migrations:latest
command: migrate apply --url ${POSTGRES_MIGRATION_DSN} --dir "file://migrations"
depends_on:
postgres:
condition: service_healthy
env_file:
- .env.prod

3 changes: 3 additions & 0 deletions .docker/migrations/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM arigaio/atlas:latest

COPY migrations /migrations
3 changes: 3 additions & 0 deletions .docker/migrations/Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM arigaio/atlas:latest

COPY migrations /migrations
7 changes: 7 additions & 0 deletions .docker/postgres/init/dbinit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e
export PGPASSWORD=postgres;
psql -v ON_ERROR_STOP=1 --username "postgres" <<-EOSQL
CREATE DATABASE whisperbot;
GRANT ALL PRIVILEGES ON DATABASE whisperbot TO "postgres";
EOSQL
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.idea
/.vscode
__debug_*
__debug_*
bot_dev.env
/.docker/db
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
up:
@docker-compose --file .docker/docker-compose.dev.yml up --build -d --remove-orphans

down:
@docker-compose --file .docker/docker-compose.dev.yml down
Empty file added migrations/.gitkeep
Empty file.

0 comments on commit 184465b

Please sign in to comment.