Skip to content

Commit

Permalink
update dockerfile to run for dev or prod (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
broneks authored Nov 27, 2024
1 parent 083709f commit 295fcb0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- main
jobs:
deploy:
if: false # disable...
# if: false # disable...
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group
Expand Down
36 changes: 28 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,35 @@
FROM golang:alpine
FROM golang:1.23.2-alpine AS builder

RUN apk update && apk add --no-cache git && apk add --no-cach bash && apk add build-base

RUN mkdir /app
WORKDIR /app

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

COPY . .

RUN go install github.com/air-verse/air@latest
RUN go mod download
RUN go build -o bin/piccolo ./cmd/piccolo

FROM golang:1.23.2-alpine AS runner

WORKDIR /root/

COPY . .
COPY --from=builder /app/bin/piccolo .

ARG ENV=production
ENV ENV=$ENV

RUN if [ "$ENV" = "local" ]; then \
go mod download; \
go install github.com/air-verse/air@latest; \
else \
go build --o bin/piccolo ./cmd/piccolo; \
fi

EXPOSE 8000
EXPOSE 8001

CMD [ "make", "run" ]
CMD if [ "$ENV" = "local" ]; then \
air; \
else \
./piccolo; \
fi
10 changes: 8 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
include .env

build:
go build --o bin/piccolo cmd/piccolo/main.go
go build --o bin/piccolo cmd/piccolo

docker_build_local:
docker build --build-arg ENV=local -t piccolo-app .

lint:
go vet ./...

run:
start_watch:
air

start:
./bin/piccolo

pg_schema:
docker compose exec postgres pg_dump -U $(DB_USER) --exclude-table-data=schema_migrations --schema-only $(DB_NAME) > db/schema.sql

Expand Down
7 changes: 6 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ services:
- DATABASE_HOST=${DB_HOST}
- DATABASE_PORT=${DB_PORT}
tty: true
build: .
build:
context: .
dockerfile: Dockerfile
args:
ENV: ${ENV}
ports:
- 8001:8001
restart: on-failure
volumes:
- .:/app
depends_on:
- postgres
- redis

postgres:
image: postgres:latest
Expand Down

0 comments on commit 295fcb0

Please sign in to comment.