Skip to content

Commit

Permalink
Merge pull request #3 from prosenjitjoy/feat/docker
Browse files Browse the repository at this point in the history
added release workflow
  • Loading branch information
prosenjitjoy authored Oct 8, 2023
2 parents de2019e + 92ade08 commit 84b5745
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
6 changes: 4 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
CONTAINER_NAME=postgres
POD_NAME=simplebank
BE_CONTAINER=prosenjitjoy/simplebank
DB_CONTAINER=postgres
DB_NAME=bankdb
DB_USER=postgres
DB_PASS=postgres
DATABASE_URL=postgres://postgres:postgres@localhost:5432/bankdb
MIGRATE_URL=pgx5://postgres:postgres@localhost:5432/bankdb
SERVER_ADDR=localhost:5000
SERVER_ADDR=:5000
SECRET_KEY=11111111222222223333333344444444
TOKEN_DURATION=15m
15 changes: 15 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Deploy to docker hub

on:
push:
branches: [ "main" ]

jobs:
build:
name: Build image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: docker build -t prosenjitjoy/simplebank .
- run: echo "${{secrets.DOCKER_PASSWORD}}" | docker login -u ${{secrets.DOCKER_USERNAME}} --password-stdin
- run: docker push prosenjitjoy/simplebank
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ci-test
name: Run unit tests

on:
push:
Expand Down
18 changes: 18 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM golang:alpine AS builder
WORKDIR /app
COPY . .
RUN go build -o main cmd/main.go
RUN apk add curl
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.16.2/migrate.linux-amd64.tar.gz | tar xvz

FROM alpine
WORKDIR /app
COPY --from=builder /app/main .
COPY --from=builder /app/migrate .
COPY database/migration ./migration
COPY start.sh .
COPY .env .

EXPOSE 5000
CMD [ "/app/main" ]
ENTRYPOINT ["/app/start.sh"]
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ run_test:
run_server:
go run main.go

.PHONY: create_container create_database delete_database open_database create_migration migrate_up migrate_up_last migrate_down migrate_down_last sqlc_generate mock_generate run_test run_server
dev_deploy:
podman pod rm -af
podman rm -af
podman pod create -p 5000:5000 ${POD_NAME}
podman pod start ${POD_NAME}
podman run --pod ${POD_NAME} --name ${DB_CONTAINER} -e POSTGRES_USER=${DB_USER} -e POSTGRES_PASSWORD=${DB_PASS} -e POSTGRES_DB=${DB_NAME} -d postgres
podman build -t ${BE_CONTAINER}:latest .
podman run --pod ${POD_NAME} --name ${BE_CONTAINER_NAME} -e DB_SOURCE=${MIGRATE_URL} ${BE_CONTAINER}:latest

.PHONY: create_container create_database delete_database open_database create_migration migrate_up migrate_up_last migrate_down migrate_down_last sqlc_generate mock_generate run_test run_server dev_deploy
9 changes: 9 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

echo "running db migration"
/app/migrate -path /app/migration -database "$DB_SOURCE" -verbose up

echo "starting the app"
exec "$@"

0 comments on commit 84b5745

Please sign in to comment.