diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ee6e240..f651ae8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,9 +9,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: 1.19.x + go-version-file: './go.mod' - name: Checkout code uses: actions/checkout@v3 @@ -19,10 +19,14 @@ jobs: id: get_version run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} - - name: Build Asset (linux) + - name: Build Asset (linux/amd64) run: CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.Version=${{ steps.get_version.outputs.VERSION }}'" -o bin/prometheus-aws-discovery-linux-amd64 ./cmd/prometheus-aws-discovery/... - - name: Build Asset (darwin) + - name: Build Asset (darwin/amd64) run: CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-X 'main.Version=${{ steps.get_version.outputs.VERSION }}'" -o bin/prometheus-aws-discovery-darwin-amd64 ./cmd/prometheus-aws-discovery/... + - name: Build Asset (linux/arm64) + run: CGO_ENABLED=0 GOOS=linux GOARCH=arm64 go build -ldflags="-X 'main.Version=${{ steps.get_version.outputs.VERSION }}'" -o bin/prometheus-aws-discovery-linux-arm64 ./cmd/prometheus-aws-discovery/... + - name: Build Asset (darwin/arm64) + run: CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -ldflags="-X 'main.Version=${{ steps.get_version.outputs.VERSION }}'" -o bin/prometheus-aws-discovery-darwin-arm64 ./cmd/prometheus-aws-discovery/... - name: Create Release id: create_release @@ -38,7 +42,7 @@ jobs: Build also available as docker image: `daspawnw/prometheus-aws-discovery:${{ steps.get_version.outputs.VERSION }}` - - name: Upload Release Asset (linux) + - name: Upload Release Asset (linux/amd64) uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -47,7 +51,7 @@ jobs: asset_path: bin/prometheus-aws-discovery-linux-amd64 asset_name: prometheus-aws-discovery-linux-amd64 asset_content_type: application/x-executable - - name: Upload Release Asset (darwin) + - name: Upload Release Asset (darwin/amd64) uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -56,6 +60,24 @@ jobs: asset_path: bin/prometheus-aws-discovery-darwin-amd64 asset_name: prometheus-aws-discovery-darwin-amd64 asset_content_type: application/x-mach-binary + - name: Upload Release Asset (linux/arm64) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: bin/prometheus-aws-discovery-linux-arm64 + asset_name: prometheus-aws-discovery-linux-arm64 + asset_content_type: application/x-executable + - name: Upload Release Asset (darwin/arm64) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: bin/prometheus-aws-discovery-darwin-arm64 + asset_name: prometheus-aws-discovery-darwin-arm64 + asset_content_type: application/x-mach-binary docker: name: Docker Push (GHCR & public ECR) @@ -81,6 +103,7 @@ jobs: - name: Docker publish uses: daspawnw/docker-multi-build-push-action@master with: + platforms: "linux/amd64,linux/arm64" docker-tag: "${{ steps.vars.outputs.tag }}" ghcr-enabled: "true" ghcr-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f835b98..1eb2d42 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,9 +8,9 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Install Go - uses: actions/setup-go@v4 + uses: actions/setup-go@v5 with: - go-version: 1.19.x + go-version-file: './go.mod' - name: Checkout code uses: actions/checkout@v3 - name: Test @@ -20,9 +20,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Install Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: - go-version: 1.19.x + go-version-file: './go.mod' - name: Checkout code uses: actions/checkout@v3 - name: Calculate coverage @@ -61,9 +61,10 @@ jobs: - name: Docker publish uses: daspawnw/docker-multi-build-push-action@master with: + platforms: "linux/amd64,linux/arm64" docker-tag: "${{ steps.vars.outputs.tag }}" ghcr-enabled: "true" ghcr-token: "${{ secrets.GITHUB_TOKEN }}" - ecr-enabled: "true" + ecr-enabled: ${{ github.repository == 'daspawnw/vault-crd' }} ecr-role-to-assume: "${{ secrets.AWS_PUBLIC_ECR_ARN }}" ecr-repository-url: "public.ecr.aws/l2l6k4u5/prometheus-aws-discovery" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index b2f8c6f..c421957 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,7 @@ -FROM golang:1.19-alpine as builder +FROM --platform=$BUILDPLATFORM golang:1.19-alpine as builder +ARG TARGETOS +ARG TARGETARCH ARG RELEASE_VERSION=development # Install our build tools @@ -7,10 +9,10 @@ RUN apk add --update git make bash ca-certificates WORKDIR /go/src/github.com/daspawnw/prometheus-aws-discovery COPY . ./ -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-X 'main.Version=${RELEASE_VERSION}'" -o bin/prometheus-aws-discovery-linux-amd64 ./cmd/prometheus-aws-discovery/... +RUN CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -ldflags="-X 'main.Version=${RELEASE_VERSION}'" -o bin/prometheus-aws-discovery ./cmd/prometheus-aws-discovery/... FROM scratch COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /go/src/github.com/daspawnw/prometheus-aws-discovery/bin/prometheus-aws-discovery-linux-amd64 /prometheus-aws-discovery +COPY --from=builder /go/src/github.com/daspawnw/prometheus-aws-discovery/bin/prometheus-aws-discovery /prometheus-aws-discovery ENTRYPOINT ["/prometheus-aws-discovery"]