From 1217c8e1f65b36eda9db2cabcf16536de8fd4c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81ngel=20Barrera=20S=C3=A1nchez?= Date: Mon, 8 Feb 2021 11:51:56 +0100 Subject: [PATCH] Add release workflow --- .github/workflows/release.yml | 92 +++++++++++++++++++++++++++++++++++ build/package/Dockerfile | 7 +-- 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c291c88 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +name: "Release" + +on: + push: + tags: + - v* + +jobs: + release: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@master + - uses: actions/setup-go@v2 + with: + go-version: '1.15.7' + + - name: Unit tests + run: go test -v ./... + + - run: | + export VERSION=${GITHUB_REF##*/} + echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV + export CURRENT_DATE=$(date --iso-8601=seconds) + echo "RELEASE_DATE=$CURRENT_DATE" >> $GITHUB_ENV + + - name: Building binaries + run: | + go mod download + mkdir binaries + cd cmd/prometheus-multi-tenant-proxy + GOOS=darwin GOARCH=amd64 go build -o prometheus-multi-tenant-proxy -ldflags="-X 'main.version=${{ env.RELEASE_VERSION }}' -X 'main.commit=${{ github.sha }}' -X 'main.date=${{ env.RELEASE_DATE }}'" + mv prometheus-multi-tenant-proxy ../../binaries/prometheus-multi-tenant-proxy-darwing-amd64 + GOOS=linux GOARCH=amd64 go build -o prometheus-multi-tenant-proxy -ldflags="-X 'main.version=${{ env.RELEASE_VERSION }}' -X 'main.commit=${{ github.sha }}' -X 'main.date=${{ env.RELEASE_DATE }}'" + mv prometheus-multi-tenant-proxy ../../binaries/prometheus-multi-tenant-proxy-linux-amd64 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to GitHub Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.REGISTRY_PASSWORD }} + - name: Build and push + uses: docker/build-push-action@v2 + with: + file: ./build/package/Dockerfile + context: . + platforms: linux/amd64,linux/arm/v7,linux/arm64 + pull: true + no-cache: true + push: true + tags: | + ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }} + ghcr.io/${{ github.repository }}:latest + build-args: | + RELEASE_DATE=${{ env.RELEASE_DATE }} + VERSION=${{ env.RELEASE_VERSION }} + COMMIT=${{ github.sha }} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ env.RELEASE_VERSION }} + release_name: Release ${{ env.RELEASE_VERSION }} + body: | + Release ${{ env.RELEASE_VERSION }} + + - name: Upload Linux release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./binaries/prometheus-multi-tenant-proxy-linux-amd64 + asset_name: prometheus-multi-tenant-proxy-linux-amd64 + asset_content_type: application/octet-stream + + - name: Upload Darwin release + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./binaries/prometheus-multi-tenant-proxy-darwing-amd64 + asset_name: prometheus-multi-tenant-proxy-darwing-amd64 + asset_content_type: application/octet-stream diff --git a/build/package/Dockerfile b/build/package/Dockerfile index 5bb579c..ba61578 100644 --- a/build/package/Dockerfile +++ b/build/package/Dockerfile @@ -1,5 +1,6 @@ FROM golang:1.15.7-buster as builder +ARG RELEASE_DATE=unknown ARG VERSION=dev ARG COMMIT=none @@ -17,11 +18,11 @@ COPY pkg pkg COPY internal internal RUN cd cmd/prometheus-multi-tenant-proxy && \ - go build -ldflags="-X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}'" + go build -ldflags="-X 'main.version=${VERSION}' -X 'main.commit=${COMMIT}' -X 'main.date=${RELEASE_DATE}'" -FROM debian:stretch +FROM debian:buster COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ COPY --from=builder /go/src/github.com/k8spin/prometheus-multi-tenant-proxy/cmd/prometheus-multi-tenant-proxy/prometheus-multi-tenant-proxy /prometheus-multi-tenant-proxy -ENTRYPOINT [ "/prometheus-multi-tenant-proxy" ] \ No newline at end of file +ENTRYPOINT [ "/prometheus-multi-tenant-proxy" ]