-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: refactoring build configurations
- Loading branch information
1 parent
693be71
commit 6f89a52
Showing
6 changed files
with
127 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,33 @@ | ||
.PHONY: up | ||
up: | ||
docker compose up -d | ||
# Developer commands | ||
.PHONY: dev-up | ||
dev-up: | ||
docker-compose -f docker-compose.dev.yml up -d | ||
|
||
.PHONY: down | ||
down: | ||
docker compose down | ||
.PHONY: dev-down | ||
dev-down: | ||
docker-compose -f docker-compose.dev.yml down | ||
|
||
.PHONY: ci | ||
ci: | ||
docker compose up -d --build api | ||
.PHONY: dev-ci | ||
dev-ci: | ||
docker-compose -f docker-compose.dev.yml up -d --build api | ||
|
||
.PHONY: runapi | ||
runapi: | ||
go run cmd/api/main.go | ||
.PHONY: dev-runapi | ||
dev-runapi: | ||
go run cmd/api/main.go | ||
|
||
# Build commands | ||
.PHONY: build-up | ||
build-up: | ||
docker-compose -f docker-compose.ci.yml up -d | ||
|
||
.PHONY: build-down | ||
build-down: | ||
docker-compose -f docker-compose.ci.yml down | ||
|
||
.PHONY: build-ci | ||
build-ci: | ||
docker-compose -f docker-compose.ci.yml up -d --build api | ||
|
||
.PHONY: build-runapi | ||
build-runapi: | ||
go run cmd/api/main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
FROM golang:1.22-alpine3.20 as builder | ||
|
||
WORKDIR /app | ||
COPY . . | ||
|
||
ENV GIN_MODE=${GIN_MODE:-release} | ||
|
||
RUN go get -d -v ./... | ||
RUN CGO_ENABLED=0 GOOS=linux go build -o api ./cmd/api/main.go | ||
|
||
FROM scratch | ||
WORKDIR / | ||
COPY --from=builder /app/api ./ | ||
|
||
ENTRYPOINT ["./api"] |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
version: '3.0' | ||
|
||
services: | ||
db: | ||
container_name: pg01 | ||
environment: | ||
- POSTGRES_HOST=${POSTGRES_HOST} | ||
- POSTGRES_PORT=${POSTGRES_PORT} | ||
- POSTGRES_USER=${POSTGRES_USER} | ||
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD} | ||
- POSTGRES_DB=${POSTGRES_DB} | ||
build: | ||
context: . | ||
dockerfile: build/db/Dockerfile-build | ||
volumes: | ||
- local_postgres_data:/var/lib/postgresql/data | ||
ports: | ||
- "${POSTGRES_PORT}:${POSTGRES_PORT}" | ||
networks: | ||
- golangnetwork | ||
healthcheck: | ||
test: ["CMD-SHELL", "pg_isready -q -d ${POSTGRES_DB} -U ${POSTGRES_USER} || exit 1"] | ||
interval: 10s | ||
timeout: 5s | ||
retries: 3 | ||
start_period: 20s | ||
|
||
migrate: | ||
image: migrate/migrate | ||
container_name: mg01 | ||
volumes: | ||
- ./migrations:/migrations | ||
command: ["-path", "/migrations", "-database", "${POSTGRES_URL}", "up"] | ||
depends_on: | ||
db: | ||
condition: service_healthy | ||
networks: | ||
- golangnetwork | ||
|
||
api: | ||
build: | ||
context: . | ||
dockerfile: build/api/Dockerfile | ||
image: app | ||
container_name: go01 | ||
restart: unless-stopped | ||
environment: | ||
- PORT=${PORT} | ||
- GIN_MODE=${GIN_MODE} | ||
- LOG_LEVEL=${LOG_LEVEL} | ||
- LOG_OUTPUT=${LOG_OUTPUT} | ||
- AUTHORIZATION_URL=${AUTHORIZATION_URL} | ||
ports: | ||
- "${PORT}:${PORT}" | ||
depends_on: | ||
- db | ||
- migrate | ||
networks: | ||
- golangnetwork | ||
|
||
volumes: | ||
local_postgres_data: {} | ||
|
||
networks: | ||
golangnetwork: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters