diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..029665b --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,53 @@ +on: + push: + tags: + - '*' +jobs: + api: + runs-on: ubuntu-latest + environment: dockerhub-push + steps: + - name: Docker login + uses: + - docker/login-action@v2 + - docker/setup-buildx-action@v2 + - actions/checkout@v3 + with: + username: hurtki + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Docker build + run: | + VERSION="${GITHUB_REF_NAME#v}" + docker buildx build --push -t hurtki/github-banners-api:${{ VERSION }} ./api/ + renderer: + runs-on: ubuntu-latest + environment: dockerhub-push + steps: + - name: Docker login + uses: + - actions/checkout@v3 + - docker/login-action@v2 + - docker/setup-buildx-action@v2 + with: + username: hurtki + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Docker build + run: | + VERSION="${GITHUB_REF_NAME#v}" + docker buildx build --push -t hurtki/github-banners-renderer:${{ VERSION }} ./renderer/ + storage: + runs-on: ubuntu-latest + environment: dockerhub-push + steps: + - name: Docker login + uses: + - actions/checkout@v3 + - docker/login-action@v2 + - docker/setup-buildx-action@v2 + with: + username: hurtki + password: ${{ secrets.DOCKER_HUB_TOKEN }} + - name: Docker build + run: | + VERSION="${GITHUB_REF_NAME#v}" + docker buildx build --push -t hurtki/github-banners-storage:${{ VERSION }} ./storage/ diff --git a/api/Dockerfile b/api/Dockerfile index 32d633d..829ca32 100644 --- a/api/Dockerfile +++ b/api/Dockerfile @@ -1,6 +1,6 @@ -FROM "golang" +FROM "golang" AS build -WORKDIR /app/renderer/ +WORKDIR /app/ COPY go.mod go.sum ./ @@ -8,10 +8,14 @@ RUN go mod download COPY . . -RUN go build -o entry +RUN CGO_ENABLED=0 go build -o entry RUN chmod u+x entry EXPOSE 80 +FROM alpine:latest + +COPY --from=build /app/entry . + CMD ["./entry"] diff --git a/renderer/Dockerfile b/renderer/Dockerfile index 32d633d..829ca32 100644 --- a/renderer/Dockerfile +++ b/renderer/Dockerfile @@ -1,6 +1,6 @@ -FROM "golang" +FROM "golang" AS build -WORKDIR /app/renderer/ +WORKDIR /app/ COPY go.mod go.sum ./ @@ -8,10 +8,14 @@ RUN go mod download COPY . . -RUN go build -o entry +RUN CGO_ENABLED=0 go build -o entry RUN chmod u+x entry EXPOSE 80 +FROM alpine:latest + +COPY --from=build /app/entry . + CMD ["./entry"] diff --git a/storage/Dockerfile b/storage/Dockerfile index 32d633d..829ca32 100644 --- a/storage/Dockerfile +++ b/storage/Dockerfile @@ -1,6 +1,6 @@ -FROM "golang" +FROM "golang" AS build -WORKDIR /app/renderer/ +WORKDIR /app/ COPY go.mod go.sum ./ @@ -8,10 +8,14 @@ RUN go mod download COPY . . -RUN go build -o entry +RUN CGO_ENABLED=0 go build -o entry RUN chmod u+x entry EXPOSE 80 +FROM alpine:latest + +COPY --from=build /app/entry . + CMD ["./entry"]