diff --git a/.github/workflows/dev-docker.yml b/.github/workflows/dev-docker.yml index def66e0325..12790251a2 100644 --- a/.github/workflows/dev-docker.yml +++ b/.github/workflows/dev-docker.yml @@ -34,62 +34,11 @@ jobs: id: vars run: echo "::set-output name=sha_short::$(git rev-parse --short HEAD)" - - name: Build (optionally publish) PeerDB Dev Image - uses: depot/build-push-action@v1 + - name: Build (optionally publish) PeerDB Images + uses: depot/bake-action@v1 with: token: ${{ secrets.DEPOT_TOKEN }} - platforms: linux/amd64,linux/arm64 - context: . - file: stacks/peerdb-server.Dockerfile + files: ./docker-bake.hcl push: ${{ github.ref == 'refs/heads/main' }} - tags: | - ghcr.io/peerdb-io/peerdb-server:dev-${{ steps.vars.outputs.sha_short }} - ghcr.io/peerdb-io/peerdb-server:latest-dev - - - name: Build (optionally publish) Flow API Dev Image - uses: depot/build-push-action@v1 - with: - token: ${{ secrets.DEPOT_TOKEN }} - platforms: linux/amd64,linux/arm64 - context: . - file: stacks/flow-api.Dockerfile - push: ${{ github.ref == 'refs/heads/main' }} - tags: | - ghcr.io/peerdb-io/flow-api:dev-${{ steps.vars.outputs.sha_short }} - ghcr.io/peerdb-io/flow-api:latest-dev - - - name: Build (optionally publish) Flow Worker Dev Image - uses: depot/build-push-action@v1 - with: - token: ${{ secrets.DEPOT_TOKEN }} - platforms: linux/amd64,linux/arm64 - context: . - file: stacks/flow-worker.Dockerfile - push: ${{ github.ref == 'refs/heads/main' }} - tags: | - ghcr.io/peerdb-io/flow-worker:dev-${{ steps.vars.outputs.sha_short }} - ghcr.io/peerdb-io/flow-worker:latest-dev - - - name: Build (optionally publish) Flow Snapshot Worker Dev Image - uses: depot/build-push-action@v1 - with: - token: ${{ secrets.DEPOT_TOKEN }} - platforms: linux/amd64,linux/arm64 - context: . - file: stacks/flow-snapshot-worker.Dockerfile - push: ${{ github.ref == 'refs/heads/main' }} - tags: | - ghcr.io/peerdb-io/flow-snapshot-worker:dev-${{ steps.vars.outputs.sha_short }} - ghcr.io/peerdb-io/flow-snapshot-worker:latest-dev - - - name: Build (optionally publish) PeerDB UI Dev Image - uses: depot/build-push-action@v1 - with: - token: ${{ secrets.DEPOT_TOKEN }} - platforms: linux/amd64,linux/arm64 - context: . - file: stacks/peerdb-ui.Dockerfile - push: ${{ github.ref == 'refs/heads/main' }} - tags: | - ghcr.io/peerdb-io/peerdb-ui:dev-${{ steps.vars.outputs.sha_short }} - ghcr.io/peerdb-io/peerdb-ui:latest-dev + set: | + *.tags="ghcr.io/peerdb-io/peerdb-server:dev-${{ steps.vars.outputs.sha_short }},ghcr.io/peerdb-io/peerdb-server:latest-dev" diff --git a/docker-bake.hcl b/docker-bake.hcl new file mode 100644 index 0000000000..0ee64c04ac --- /dev/null +++ b/docker-bake.hcl @@ -0,0 +1,57 @@ +group "default" { + targets = [ + "peerdb", + "flow-worker", + "flow-api", + "flow-snapshot-worker", + "peerdb-ui" + ] +} + +target "flow-api" { + context = "." + dockerfile = "stacks/flow.Dockerfile" + target = "flow-api" + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} + +target "flow-snapshot-worker" { + context = "." + dockerfile = "stacks/flow.Dockerfile" + target = "flow-snapshot-worker" + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} + +target "flow-worker" { + context = "." + dockerfile = "stacks/flow.Dockerfile" + target = "flow-worker" + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} + +target "peerdb" { + context = "." + dockerfile = "stacks/peerdb-server.Dockerfile" + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} + +target "peerdb-ui" { + context = "." + dockerfile = "stacks/peerdb-ui.Dockerfile" + platforms = [ + "linux/amd64", + "linux/arm64", + ] +} diff --git a/docker-compose.yml b/docker-compose.yml index 9085191e34..1bad765a58 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -106,7 +106,8 @@ services: container_name: flow_api build: context: . - dockerfile: stacks/flow-api.Dockerfile + dockerfile: stacks/flow.Dockerfile + target: flow-api ports: - 8112:8112 - 8113:8113 @@ -121,7 +122,8 @@ services: container_name: flow-snapshot-worker build: context: . - dockerfile: stacks/flow-snapshot-worker.Dockerfile + dockerfile: stacks/flow.Dockerfile + target: flow-snapshot-worker environment: <<: [*peerdb-temporal-namespace] TEMPORAL_HOST_PORT: temporal:7233 @@ -133,7 +135,8 @@ services: container_name: flow-worker1 build: context: . - dockerfile: stacks/flow-worker.Dockerfile + dockerfile: stacks/flow.Dockerfile + target: flow-worker environment: <<: [*catalog-config, *flow-worker-env, *peerdb-temporal-namespace] METRICS_SERVER: 0.0.0.0:6061 diff --git a/stacks/flow-api.Dockerfile b/stacks/flow-api.Dockerfile deleted file mode 100644 index 22af707554..0000000000 --- a/stacks/flow-api.Dockerfile +++ /dev/null @@ -1,45 +0,0 @@ -# syntax=docker/dockerfile:1.2 - -# Start from the latest Golang base image -FROM golang:1.21.3-bookworm AS builder - -RUN apt-get update && apt-get install -y gcc - -RUN apt-get update && apt-get install -y libgeos-dev -WORKDIR /root/flow - -# first copy only go.mod and go.sum to cache dependencies -COPY flow/go.mod . -COPY flow/go.sum . - -# download all the dependencies -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -# Copy all the code -COPY flow . - -# build the binary from cmd folder -WORKDIR /root/flow/cmd -RUN --mount=type=cache,target=/root/.cache/go-build \ - CGO_ENABLED=1 go build -ldflags="-s -w" -o /root/peer-flow . - -FROM golang:1.21.3-bookworm -RUN apt-get update && apt-get install -y ca-certificates - -RUN apt-get update && apt-get install -y gcc - -# install lib geos dev -RUN apt-get update && apt-get install -y libgeos-dev -WORKDIR /root -COPY --from=builder /root/peer-flow . -EXPOSE 8112 -EXPOSE 8113 -ENTRYPOINT [\ - "./peer-flow",\ - "api",\ - "--port",\ - "8112",\ - "--gateway-port",\ - "8113"\ - ] diff --git a/stacks/flow-snapshot-worker.Dockerfile b/stacks/flow-snapshot-worker.Dockerfile deleted file mode 100644 index 0383a03745..0000000000 --- a/stacks/flow-snapshot-worker.Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -# syntax=docker/dockerfile:1.2 - -# Start from the latest Golang base image -FROM golang:1.21.3-bookworm AS builder - -RUN apt-get update && apt-get install -y gcc - -RUN apt-get update && apt-get install -y libgeos-dev - - -WORKDIR /root/ - -# first copy only go.mod and go.sum to cache dependencies -COPY flow/go.mod . -COPY flow/go.sum . - -# download all the dependencies -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -COPY flow . - -# build the binary from cmd folder -WORKDIR /root/cmd -RUN --mount=type=cache,target=/root/.cache/go-build \ - CGO_ENABLED=1 go build -ldflags="-s -w" -o /root/peer-flow . - -FROM golang:1.21.3-bookworm -RUN apt-get update && apt-get install -y ca-certificates - -RUN apt-get update && apt-get install -y gcc -# install lib geos dev -RUN apt-get update && apt-get install -y libgeos-dev -WORKDIR /root -COPY --from=builder /root/peer-flow . -EXPOSE 8112 -ENTRYPOINT ["./peer-flow", "snapshot-worker"] diff --git a/stacks/flow-worker.Dockerfile b/stacks/flow-worker.Dockerfile deleted file mode 100644 index 526fb59d45..0000000000 --- a/stacks/flow-worker.Dockerfile +++ /dev/null @@ -1,37 +0,0 @@ -# syntax=docker/dockerfile:1.2 - -# Start from the latest Golang base image -FROM golang:1.21.3-bookworm AS builder - -RUN apt-get update && apt-get install -y gcc - -RUN apt-get update && apt-get install -y libgeos-dev - -WORKDIR /root/ - -# first copy only go.mod and go.sum to cache dependencies -COPY flow/go.mod . -COPY flow/go.sum . - -# download all the dependencies -RUN --mount=type=cache,target=/go/pkg/mod \ - go mod download - -COPY flow . - -# build the binary from cmd folder -WORKDIR /root/cmd -RUN --mount=type=cache,target=/root/.cache/go-build \ - CGO_ENABLED=1 go build -ldflags="-s -w"\ - -o /root/peer-flow . - -FROM golang:1.21.3-bookworm -RUN apt-get update && apt-get install -y ca-certificates - -RUN apt-get update && apt-get install -y gcc -# install lib geos dev -RUN apt-get update && apt-get install -y libgeos-dev -WORKDIR /root -COPY --from=builder /root/peer-flow . -EXPOSE 8112 -ENTRYPOINT ["./peer-flow", "worker"] diff --git a/stacks/flow.Dockerfile b/stacks/flow.Dockerfile new file mode 100644 index 0000000000..d04b307394 --- /dev/null +++ b/stacks/flow.Dockerfile @@ -0,0 +1,49 @@ +# syntax=docker/dockerfile:1.2 + +FROM golang:1.21.3-bookworm AS builder +RUN apt-get update && apt-get install -y gcc libgeos-dev +WORKDIR /root/flow + +# first copy only go.mod and go.sum to cache dependencies +COPY flow/go.mod . +COPY flow/go.sum . + +# download all the dependencies +RUN go mod download + +# Copy all the code +COPY flow . + +# build the binary from cmd folder +WORKDIR /root/flow/cmd +ENV CGO_ENABLED=1 +RUN go build -ldflags="-s -w" -o /root/peer-flow . + +FROM debian:bookworm-slim AS flow-base +RUN apt-get update && apt-get install -y ca-certificates gcc libgeos-dev +WORKDIR /root +COPY --from=builder /root/peer-flow . + +FROM flow-base AS flow-api +EXPOSE 8112 +EXPOSE 8113 +ENTRYPOINT [\ + "./peer-flow",\ + "api",\ + "--port",\ + "8112",\ + "--gateway-port",\ + "8113"\ + ] + +FROM flow-base AS flow-worker +ENTRYPOINT [\ + "./peer-flow",\ + "worker"\ + ] + +FROM flow-base AS flow-snapshot-worker +ENTRYPOINT [\ + "./peer-flow",\ + "snapshot-worker"\ + ]