Skip to content

Commit

Permalink
build multiarch images (#319)
Browse files Browse the repository at this point in the history
* try buildx

* try using the build-and-push action
  • Loading branch information
tommyzli authored May 6, 2024
1 parent a5000b7 commit 4b6fe92
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 41 deletions.
57 changes: 17 additions & 40 deletions .github/workflows/build-test-publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -369,18 +369,6 @@ jobs:
path: ./bin/*

publish-dev:
strategy:
matrix:
os:
#- darwin
- linux
#- windows
arch:
#- 386
- amd64
#- arm
- arm64
#- ppc64le
permissions:
contents: 'read'
id-token: 'write'
Expand All @@ -394,6 +382,10 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: "1.20"
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Mkdir bin and dist
run: |
mkdir bin/ dist/
Expand Down Expand Up @@ -423,23 +415,14 @@ jobs:
BRANCH: ${{github.ref_name}}
RUN_NUMBER: ${{github.run_number}}
BASE_VERSION: "0.0.0"
GOARCH: ${{ matrix.arch }}
GOOS: ${{ matrix.os }}
run: |
# let's simply use the k8s namespace rules (even stricter) and have the same version(-suffix) for everything
# lowercase everything and replace all invalid characters with '-' and trim to 60 characters
SANITIZED_BRANCH=$(echo -n "${BRANCH}" | tr '[:upper:]' '[:lower:]' | tr -C 'a-z0-9' '-')
SANITIZED_BRANCH="${SANITIZED_BRANCH:0:60}"
BUILD_VERSION="${BASE_VERSION}-${SANITIZED_BRANCH}-${RUN_NUMBER}-${GOOS}-${GOARCH}"
BUILD_VERSION="${BASE_VERSION}-${SANITIZED_BRANCH}-${RUN_NUMBER}"
echo "BUILD_VERSION=${BUILD_VERSION}" | tee -a $GITHUB_ENV $GITHUB_OUTPUT
- name: Build Docker Image
env:
GOARCH: ${{ matrix.arch }}
GOOS: ${{ matrix.os }}
run: |
make docker-otelcontribcol
docker tag otelcontribcol:latest 609927696493.dkr.ecr.us-west-2.amazonaws.com/opentelemetry-collector-contrib:${{ steps.create-version.outputs.BUILD_VERSION }}
- id: login-gcp
name: Authenticate with Google Cloud
uses: google-github-actions/auth@v1
Expand Down Expand Up @@ -475,21 +458,15 @@ jobs:
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Push Docker Image
run: |
docker push 609927696493.dkr.ecr.us-west-2.amazonaws.com/opentelemetry-collector-contrib:${{ steps.create-version.outputs.BUILD_VERSION }}
- name: Push image to GCP
env:
DOCKER_IMAGE: otelcontribcol
BUILD_VERSION: ${{steps.create-version.outputs.BUILD_VERSION}}
GCR_ASIA_IMAGE: ${{secrets.GCR_ASIA_IMAGE}}
GCR_EUROPE_IMAGE: ${{secrets.GCR_EUROPE_IMAGE}}
GCR_US_IMAGE: ${{secrets.GCR_US_IMAGE}}
run: |
docker tag $DOCKER_IMAGE:latest ${GCR_ASIA_IMAGE}:${BUILD_VERSION}
docker tag $DOCKER_IMAGE:latest ${GCR_EUROPE_IMAGE}:${BUILD_VERSION}
docker tag $DOCKER_IMAGE:latest ${GCR_US_IMAGE}:${BUILD_VERSION}
docker push -a ${GCR_ASIA_IMAGE}
docker push -a ${GCR_EUROPE_IMAGE}
docker push -a ${GCR_US_IMAGE}
- name: build and push
uses: docker/build-push-action@v5
with:
push: true
context: .
file: ./cmd/otelcontribcol/Dockerfile
platforms: linux/amd64,linux/arm64
tags: |
609927696493.dkr.ecr.us-west-2.amazonaws.com/opentelemetry-collector-contrib:${{steps.create-version.outputs.BUILD_VERSION}}
${{secrets.GCR_ASIA_IMAGE}}:${{steps.create-version.outputs.BUILD_VERSION}}
${{secrets.GCR_EUROPE_IMAGE}}:${{steps.create-version.outputs.BUILD_VERSION}}
${{secrets.GCR_US_IMAGE}}:${{steps.create-version.outputs.BUILD_VERSION}}
9 changes: 8 additions & 1 deletion cmd/otelcontribcol/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
FROM golang:1.20 AS build

WORKDIR /src
ADD . /src

RUN cd cmd/otelcontribcol && CGO_ENABLED=0 go build -o /otelcontribcol

FROM alpine:latest as prep
RUN apk --update add ca-certificates

Expand All @@ -9,7 +16,7 @@ ARG USER_UID=10001
USER ${USER_UID}

COPY --from=prep /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY otelcontribcol /
COPY --from=build /otelcontribcol /otelcontribcol
EXPOSE 4317 55680 55679
ENTRYPOINT ["/otelcontribcol"]
CMD ["--config", "/etc/otel/config.yaml"]

0 comments on commit 4b6fe92

Please sign in to comment.