diff options
author | Santo Cariotti <santo@dcariotti.me> | 2025-04-22 09:39:17 +0200 |
---|---|---|
committer | Santo Cariotti <santo@dcariotti.me> | 2025-04-22 09:39:17 +0200 |
commit | d9dfabe75e4edb7fe2f32cb9a42113a529f52bf6 (patch) | |
tree | 64aaa67b55628dc7120ba6a140b49b2d5ed4bdb8 | |
parent | 2ce3cb9fdb90847a33106c61708f516ea6ca932a (diff) |
Add Docker
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | docker/api/Dockerfile | 22 | ||||
-rw-r--r-- | docker/api/docker-compose.yml | 35 | ||||
-rw-r--r-- | docker/ui/Dockerfile | 21 |
4 files changed, 96 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..948a57e --- /dev/null +++ b/Makefile @@ -0,0 +1,18 @@ +.PHONY: all build-api build-ui docker-api docker-ui clean + +all: build-api build-ui docker-api docker-ui + +build-api: + @go build -o rahanna-api cmd/api/main.go + +build-ui: + @go build -o rahanna-ui cmd/ui/main.go + +docker-api: + @docker build -t rahanna-api:latest -f docker/api/Dockerfile . + +docker-ui: + @docker build -t rahanna-ui:latest -f docker/ui/Dockerfile . + +clean: + -@docker rmi -f rahanna-api rahanna-ui diff --git a/docker/api/Dockerfile b/docker/api/Dockerfile new file mode 100644 index 0000000..c92d35a --- /dev/null +++ b/docker/api/Dockerfile @@ -0,0 +1,22 @@ +FROM golang:alpine AS builder + +RUN apk --update add ca-certificates git + +WORKDIR /app + +COPY . . +RUN go mod download + +RUN CGO_ENABLED=0 GOOS=linux go build cmd/api/main.go + +# Run the exe file +FROM scratch + +WORKDIR /app + +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt +COPY --from=builder /app . + +EXPOSE 8080 + +CMD ["./main"] diff --git a/docker/api/docker-compose.yml b/docker/api/docker-compose.yml new file mode 100644 index 0000000..53c105f --- /dev/null +++ b/docker/api/docker-compose.yml @@ -0,0 +1,35 @@ +services: + postgres: + image: postgres:16-alpine + container_name: rahanna-postgres + restart: always + environment: + - POSTGRES_DB=${POSTGRES_DB} + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + networks: + - default + volumes: + - postgres_data:/var/lib/postgresql/data + + rahanna: + image: rahanna-api + container_name: rahanna-api + networks: + - default + environment: + - DATABASE_URL=${DATABASE_URL} + - JWT_TOKEN=${JWT_TOKEN} + - API_ADDRESS=:8080 + - DEBUG=0 + depends_on: + - postgres + ports: + - "8080:8080" + restart: unless-stopped + +networks: + default: + +volumes: + postgres_data: diff --git a/docker/ui/Dockerfile b/docker/ui/Dockerfile new file mode 100644 index 0000000..cccf52c --- /dev/null +++ b/docker/ui/Dockerfile @@ -0,0 +1,21 @@ +# Build stage +FROM golang:alpine AS builder + +RUN apk --update add ca-certificates git + +WORKDIR /app + +COPY go.mod go.sum ./ +RUN go mod download + +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o rahanna-ui cmd/ui/main.go + +# Run stage +FROM alpine:latest + +WORKDIR /app + +COPY --from=builder /app/rahanna-ui . + +CMD ["./rahanna-ui"] |