diff --git a/nginx-golang-mysql/.docker/docker-compose.yaml b/nginx-golang-mysql/.docker/docker-compose.yaml new file mode 100644 index 0000000..2b04dd0 --- /dev/null +++ b/nginx-golang-mysql/.docker/docker-compose.yaml @@ -0,0 +1,50 @@ +services: + backend: + build: + context: backend + target: builder + volumes: + - /var/run/docker.sock:/var/run/docker.sock + secrets: + - db-password + depends_on: + db: + condition: service_healthy + + db: + image: mariadb:10-focal + command: '--default-authentication-plugin=mysql_native_password' + restart: always + healthcheck: + test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "--silent"] + interval: 3s + retries: 5 + start_period: 30s + secrets: + - db-password + volumes: + - db-data:/var/lib/mysql + environment: + - MYSQL_DATABASE=example + - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db-password + expose: + - 3306 + + proxy: + image: nginx + volumes: + - type: bind + source: ./proxy/nginx.conf + target: /etc/nginx/conf.d/default.conf + read_only: true + ports: + - 80:80 + depends_on: + - backend + +volumes: + db-data: + +secrets: + db-password: + file: db/password.txt diff --git a/nginx-golang-mysql/backend/Dockerfile b/nginx-golang-mysql/backend/Dockerfile index 36e9525..6f794aa 100755 --- a/nginx-golang-mysql/backend/Dockerfile +++ b/nginx-golang-mysql/backend/Dockerfile @@ -1,10 +1,41 @@ -FROM golang:1.13-alpine AS build -WORKDIR /go/src/github.com/org/repo +# syntax=docker/dockerfile:1.4 +FROM --platform=$BUILDPLATFORM golang:1.18-alpine AS builder + +WORKDIR /code + +ENV CGO_ENABLED 0 +ENV GOPATH /go +ENV GOCACHE /go-build + +COPY go.mod go.sum ./ +RUN --mount=type=cache,target=/go/pkg/mod/cache \ + go mod download + COPY . . -RUN go build -o server . +RUN --mount=type=cache,target=/go/pkg/mod/cache \ + --mount=type=cache,target=/go-build \ + go build -o bin/backend main.go -FROM alpine:3.12 -EXPOSE 8000 -COPY --from=build /go/src/github.com/org/repo/server /server -CMD ["/server"] +CMD ["/code/bin/backend"] + +FROM builder as dev-envs + +RUN <