diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 57369dd..e69aa67 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -15,20 +15,23 @@ jobs: with: fetch-depth: 0 - - name: Build 🏗️ - id: build - uses: szkiba/xk6bundler@v0 - with: - platform: linux/amd64 windows/amd64 darwin/amd64 - with: | - github.com/mostafa/xk6-kafka@${{ github.ref_name }} - - name: Install Go 🧑‍💻 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') uses: actions/setup-go@v3 with: go-version: '1.18' + - name: Install xk6 and build xk6-kafka for different platforms 🏗️ + run: | + mkdir dist + go install go.k6.io/xk6/cmd/xk6@latest + GOOS=linux GOARCH=amd64 xk6 build --output dist/xk6-kafka_${{ github.ref_name }}_linux_amd64 --with github.com/mostafa/xk6-kafka@${{ github.ref_name }} + tar cvzf dist/xk6-kafka_${{ github.ref_name }}_linux_amd64.tar.gz dist/xk6-kafka_${{ github.ref_name }}_linux_amd64 + GOOS=darwin GOARCH=amd64 xk6 build --output dist/xk6-kafka_${{ github.ref_name }}_darwin_amd64 --with github.com/mostafa/xk6-kafka@${{ github.ref_name }} + tar cvzf dist/xk6-kafka_${{ github.ref_name }}_darwin_amd64.tar.gz dist/xk6-kafka_${{ github.ref_name }}_darwin_amd64 + GOOS=windows GOARCH=amd64 xk6 build --output dist/xk6-kafka_${{ github.ref_name }}_windows_amd64.exe --with github.com/mostafa/xk6-kafka@${{ github.ref_name }} + tar cvzf dist/xk6-kafka_${{ github.ref_name }}_windows_amd64.tar.gz dist/xk6-kafka_${{ github.ref_name }}_windows_amd64.exe + - name: Generate CycloneDX SBOM artifacts 📃 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') run: | @@ -50,9 +53,9 @@ jobs: - name: Docker meta 📝 id: meta - uses: docker/metadata-action@v3 + uses: docker/metadata-action@v4 with: - images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ steps.build.outputs.name }} + images: mostafamoradian/xk6-kafka tags: | type=semver,pattern={{version}} @@ -62,12 +65,13 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Docker build and push ☁️ + - name: Build and push Docker image 🛳️ if: startsWith(github.ref, 'refs/tags/') uses: docker/build-push-action@v2 with: + context: . push: true - context: ./${{ steps.build.outputs.dockerdir }} + build-args: K6_BINARY=./dist/xk6-kafka_${{ github.ref_name }}_linux_amd64 tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 344f42e..80d3cd4 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ k6 .idea act __debug_bin - +dist/ diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f96d871 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine +ARG K6_BINARY + +RUN apk add --no-cache ca-certificates && \ + adduser -D -u 12345 -g 12345 k6 +COPY ${K6_BINARY} /usr/bin/k6 + +USER 12345 +WORKDIR /home/k6 +ENTRYPOINT ["k6"]