diff --git a/.github/workflows/build-and-publish.yml b/.github/workflows/build-and-publish.yml index 2089c78..6e3cd7d 100644 --- a/.github/workflows/build-and-publish.yml +++ b/.github/workflows/build-and-publish.yml @@ -5,7 +5,7 @@ on: pull_request: branches: [main] paths: - - .github/workflows/jaeger-dockerimage.yml + - .github/workflows/build-and-publish.yml - Dockerfile - protoc-wrapper release: @@ -19,19 +19,27 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-qemu-action@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 + - uses: docker/setup-buildx-action@v3 with: install: true + driver-opts: | + network=host + + - name: Start local Docker registry + if: ${{ github.event_name == 'pull_request' }} + run: | + docker inspect registry > /dev/null || docker run --rm -d -p 5000:5000 --name registry registry:2 - name: Extract tags/labels from Git id: docker_meta uses: docker/metadata-action@v5 with: - images: jaegertracing/protobuf + # when running on pull request we want to push the image to local registry for further testing + images: | + jaegertracing/protobuf,enable=${{ github.event_name != 'pull_request' }} + localhost:5000/jaegertracing/protobuf,enable=${{ github.event_name == 'pull_request' }} # The 'tags:' section defines how the Docker image will be tagged: # - pushes to main branch will be published as 'latest' # - pushes tagged with semver will be published as that version (without 'v') @@ -41,6 +49,7 @@ jobs: type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} type=semver,pattern={{version}} type=ref,event=tag + type=sha,enable=${{ github.event_name == 'pull_request' }} - name: Login to DockerHub if: github.event_name != 'pull_request' @@ -50,11 +59,12 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Build and maybe push Docker image - uses: docker/build-push-action@v5 + uses: docker/build-push-action@v6 with: - push: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') }} + push: true tags: ${{ steps.docker_meta.outputs.tags }} labels: ${{ steps.docker_meta.outputs.labels }} + context: . cache-from: type=gha cache-to: type=gha,mode=max platforms: linux/amd64,linux/arm64 @@ -64,6 +74,10 @@ jobs: # We do not check if the generated files would be different there, # only that the build does not fail. + - name: Pull image for local testing + if: github.event_name == 'pull_request' + run: docker pull ${{ steps.docker_meta.outputs.tags }} + - name: Checkout Jaeger for validation if: github.event_name == 'pull_request' uses: actions/checkout@v4 @@ -75,7 +89,7 @@ jobs: - name: Build Proto in Jaeger if: github.event_name == 'pull_request' working-directory: jaeger - run: make proto JAEGER_DOCKER_PROTOBUF=protobuf + run: make proto DOCKER_PROTOBUF=${{ steps.docker_meta.outputs.tags }} - name: Checkout jaeger-idl for validation if: github.event_name == 'pull_request' @@ -88,4 +102,4 @@ jobs: - name: Build Proto in jaeger-idl if: github.event_name == 'pull_request' working-directory: jaeger-idl - run: make proto PROTOC_IMAGE=protobuf + run: make proto PROTOC_IMAGE=${{ steps.docker_meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 7c63f2b..0a479ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,11 +11,11 @@ ARG PROTOC_GEN_GOGO_VERSION=b03c65ea87cdc3521ede29f62fe3ce239267c1bc ARG PROTOC_GEN_LINT_VERSION=0.2.1 ARG UPX_VERSION=3.96 -FROM alpine:${ALPINE_VERSION} as protoc_base +FROM alpine:${ALPINE_VERSION} AS protoc_base RUN apk add --no-cache build-base curl cmake autoconf libtool git zlib-dev linux-headers && \ mkdir -p /out -FROM protoc_base as protoc_builder +FROM protoc_base AS protoc_builder ARG GRPC_VERSION RUN apk add --no-cache automake ninja && \ git clone --recursive --depth=1 -b v${GRPC_VERSION} https://github.com/grpc/grpc.git /grpc && \ @@ -77,7 +77,7 @@ RUN git clone --recursive --depth=1 -b v${GRPC_CSHARP_VERSION} https://github.co rm -Rf /grpc -FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} as go_builder +FROM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS go_builder RUN apk add --no-cache build-base curl git ENV GOBIN=/out/usr/bin @@ -119,7 +119,7 @@ RUN mkdir -p ${GOPATH}/src/github.com/grpc-ecosystem/grpc-gateway && \ install -D $(find ./third_party/googleapis/google/rpc -name '*.proto') -t /out/usr/include/google/rpc -FROM alpine:${ALPINE_VERSION} as packer +FROM alpine:${ALPINE_VERSION} AS packer RUN apk add --no-cache curl ARG UPX_VERSION