Skip to content

Commit

Permalink
Add support for building the Docker image for linux/arm64 (#278)
Browse files Browse the repository at this point in the history
Update gh-actions
Update Go to v1.22
Update Dockerfile to build for multiple platforms and archs
  • Loading branch information
mostafa authored Mar 18, 2024
1 parent dd7c467 commit d0e73cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go 🧑‍💻
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- name: Install xk6 and build xk6-kafka for different platforms 🏗️
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
Expand Down Expand Up @@ -48,20 +48,27 @@ jobs:
tags: |
type=semver,pattern={{version}}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub 🔒
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image 🛳️
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
push: true
build-args: K6_BINARY=./dist/xk6-kafka_${{ github.ref_name }}_linux_amd64
push: false
platforms: linux/amd64,linux/arm64
build-args: VERSION_TAG=${{ github.ref_name }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install Go 🧑‍💻
uses: actions/setup-go@v3
uses: actions/setup-go@v5
with:
go-version: "1.21"
go-version: "1.22"

- name: Run prettier for linting scripts, configs and docs 🧹
uses: creyD/prettier_action@v4.3
with:
dry: True

- name: Lint code issues 🚨
uses: golangci/golangci-lint-action@v3
uses: golangci/golangci-lint-action@v4
with:
skip-pkg-cache: true

Expand Down
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
FROM alpine
ARG K6_BINARY

ARG VERSION_TAG
ARG TARGETOS
ARG TARGETARCH

RUN apk add --no-cache ca-certificates && \
adduser -D -u 12345 -g 12345 k6
COPY ${K6_BINARY} /usr/bin/k6
COPY ./dist/xk6-kafka_${VERSION_TAG}_${TARGETOS}_${TARGETARCH} /usr/bin/k6

USER 12345
WORKDIR /home/k6
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mostafa/xk6-kafka

go 1.21
go 1.22

require (
github.com/aws/aws-sdk-go-v2/config v1.18.39
Expand Down

0 comments on commit d0e73cc

Please sign in to comment.