From 6587709767a61a643afc94094784323333b718a6 Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Tue, 5 May 2020 08:47:24 +0200 Subject: [PATCH 1/2] Updated GitHub actions to use matrix --- .github/workflows/master.yml | 75 +++++++++---------- .github/workflows/tag.yml | 135 +++++++++++++++++++++++++---------- Dockerfile | 2 +- 3 files changed, 137 insertions(+), 75 deletions(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index b1d8043..78bda06 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -1,47 +1,50 @@ -name: Build and Publish (master) +name: Build/Push (master) on: push: - branches: [ master ] + branches: [ ci ] pull_request: - branches: [ master ] + branches: [ ci ] jobs: - build-amd64: + test: runs-on: ubuntu-latest + strategy: + matrix: + go_version: [ '1.12', '1.13', '1.14' ] steps: - - uses: actions/checkout@v2 - - name: Build and Push Docker Image (Linux - AMD64) - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: amd64 - build_args: OS=linux,ARCH=amd64,IMAGE=scratch + - uses: actions/checkout@v2 + - uses: actions/setup-go@v1 + with: + go-version: ${{ matrix.go_version }} + - run: go get -t -v ./... + - run: go test -v -race ./... - build-arm32: + build: runs-on: ubuntu-latest + needs: test + strategy: + matrix: + include: + - os: linux + arch: amd64 + image: scratch + - os: linux + arch: arm + image: arm32v7/alpine:3.11 + - os: linux + arch: arm64 + image: arm64v8/alpine:3.11 + steps: - - uses: actions/checkout@v2 - - name: Build and Push Docker Image (Linux - ARM32) - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: arm32 - build_args: OS=linux,ARCH=arm,IMAGE=arm32v7/alpine:3.11 - - build-arm64: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Build and Push Docker Image (Linux - ARM64) - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: arm64 - build_args: OS=linux,ARCH=arm64,IMAGE=arm64v8/alpine:3.11 + - uses: actions/checkout@v2 + + - name: Build/Push docker image (${{ matrix.os }}/${{ matrix.arch }}) + uses: docker/build-push-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + repository: ekofr/pihole-exporter + tags: ${{ matrix.arch }} + build_args: OS=${{ matrix.os }},ARCH=${{ matrix.arch }},IMAGE=${{ matrix.image }} + diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 70c8923..594c58d 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -1,55 +1,114 @@ -name: Build and Publish (tag) +name: Build/Push (tag) on: push: - tags: - - '*' + branches: [ ci ] + pull_request: + branches: [ ci ] +#on: +# push: +# tags: +# - '*' jobs: - build-amd64: + test: runs-on: ubuntu-latest + strategy: + matrix: + go_version: [ '1.12', '1.13', '1.14' ] steps: - - uses: actions/checkout@v2 - - name: Get the version - id: get_version - run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//} - - name: Build and Push Docker Image (Linux - AMD64) - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: amd64,${{ steps.get_version.outputs.TAG_NAME }} - build_args: OS=linux,ARCH=amd64,IMAGE=scratch + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go_version }} + - run: go get -t -v ./... + - run: go test -v -race ./... - build-arm32: + build: runs-on: ubuntu-latest + needs: test steps: - uses: actions/checkout@v2 - - name: Get the version - id: get_version - run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//} - - name: Build and Push Docker Image (Linux - ARM32) - uses: docker/build-push-action@v1 + + - uses: azure/docker-login@v1 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: arm32,${{ steps.get_version.outputs.TAG_NAME }} - build_args: OS=linux,ARCH=arm,IMAGE=arm32v7/alpine:3.11 - - build-arm64: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 + + - name: Set up docker buildx + id: buildx + uses: crazy-max/ghaction-docker-buildx@v1 + with: + buildx-version: latest + qemu-version: latest + + - name: Docker buildx available platforms + run: echo ${{ steps.buildx.outputs.platforms }} + - name: Get the version id: get_version run: echo ::set-output name=TAG_NAME::${GITHUB_REF/refs\/tags\//} - - name: Build and Push Docker Image (Linux - ARM64) - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ekofr/pihole-exporter - tags: arm64,${{ steps.get_version.outputs.TAG_NAME }} - build_args: OS=linux,ARCH=arm64,IMAGE=arm64v8/alpine:3.11 + + - name: Run docker buildx build + run: | + docker buildx build \ + --platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \ + --output=type=registry \ + --tag ekofr/pihole-exporter:${{ steps.get_version.outputs.TAG_NAME }} \ + . + + release: + runs-on: ubuntu-latest + needs: test + steps: + - name: Create release + id: create + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + + push: + runs-on: ubuntu-latest + needs: release + strategy: + matrix: + include: + - os: linux + arch: 386 + - os: linux + arch: amd64 + - os: linux + arch: arm + - os: darwin + arch: 386 + - os: darwin + arch: amd64 + - os: windows + arch: 386 + - os: windows + arch: amd64 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: 1.14 + - run: go get -t -v ./... + + - run: go install github.com/mitchellh/gox + - run: gox -ldflags "-s -w" -os="${{ matrix.os }}" -arch="${{ matrix.arch }}" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./... + + - name: Upload release assets + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create.outputs.upload_url }} + asset_path: ./pihole_exporter-${{ matrix.os }}-${{ matrix.arch }} + asset_name: pihole_exporter-${{ matrix.os }}-${{ matrix.arch }} + asset_content_type: application/octet-stream diff --git a/Dockerfile b/Dockerfile index 1207b0b..1b0115e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN apk update && \ RUN GO111MODULE=on go mod vendor RUN CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -ldflags '-s -w' -o binary ./ -RUN upx -f --brute binary +#RUN upx -f --brute binary FROM $IMAGE From dce933052348ef715e4af07a2eaa6e3fe0f3d40b Mon Sep 17 00:00:00 2001 From: Vincent Composieux Date: Tue, 5 May 2020 13:32:37 +0200 Subject: [PATCH 2/2] Replace Travis-CI with GitHub actions and use docker buildx --- .github/workflows/master.yml | 16 +++++++++----- .github/workflows/tag.yml | 32 +++++++++++++++------------ .travis.yml | 42 ------------------------------------ Dockerfile | 2 +- 4 files changed, 30 insertions(+), 62 deletions(-) delete mode 100644 .travis.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 78bda06..749fa4a 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -2,9 +2,11 @@ name: Build/Push (master) on: push: - branches: [ ci ] + branches: + - '*' pull_request: - branches: [ ci ] + branches: + - '*' jobs: test: @@ -17,8 +19,12 @@ jobs: - uses: actions/setup-go@v1 with: go-version: ${{ matrix.go_version }} - - run: go get -t -v ./... - - run: go test -v -race ./... + + - name: Install go dependencies + run: go get -t -v ./... + + - name: Run go tests + run: go test -v -cover -race ./... build: runs-on: ubuntu-latest @@ -39,7 +45,7 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Build/Push docker image (${{ matrix.os }}/${{ matrix.arch }}) + - name: Build and push docker image (${{ matrix.os }}/${{ matrix.arch }}) uses: docker/build-push-action@v1 with: username: ${{ secrets.DOCKER_USERNAME }} diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index 594c58d..320007e 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -2,13 +2,8 @@ name: Build/Push (tag) on: push: - branches: [ ci ] - pull_request: - branches: [ ci ] -#on: -# push: -# tags: -# - '*' + tags: + - '*' jobs: test: @@ -71,8 +66,10 @@ jobs: release_name: ${{ github.ref }} draft: false prerelease: false + outputs: + upload_url: ${{ steps.create.outputs.upload_url }} - push: + upload: runs-on: ubuntu-latest needs: release strategy: @@ -90,17 +87,24 @@ jobs: arch: amd64 - os: windows arch: 386 + extension: '.exe' - os: windows arch: amd64 + extension: '.exe' steps: - uses: actions/checkout@v2 - uses: actions/setup-go@v2 with: go-version: 1.14 - - run: go get -t -v ./... - - run: go install github.com/mitchellh/gox - - run: gox -ldflags "-s -w" -os="${{ matrix.os }}" -arch="${{ matrix.arch }}" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./... + - name: Download go dependencies + run: go get -t -v ./... + + - name: Install mitchellh/gox to create platform specific releases + run: go install github.com/mitchellh/gox + + - name: Create release + run: gox -ldflags "-s -w" -os="${{ matrix.os }}" -arch="${{ matrix.arch }}" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./... - name: Upload release assets id: upload-release-asset @@ -108,7 +112,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - upload_url: ${{ steps.create.outputs.upload_url }} - asset_path: ./pihole_exporter-${{ matrix.os }}-${{ matrix.arch }} - asset_name: pihole_exporter-${{ matrix.os }}-${{ matrix.arch }} + upload_url: ${{ needs.release.outputs.upload_url }}${{ matrix.extension }} + asset_path: ./pihole_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} + asset_name: pihole_exporter-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.extension }} asset_content_type: application/octet-stream diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 5596ff7..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -language: go -matrix: - include: - - go: 1.x - env: LATEST=true - - go: 1.9.x - - go: 1.10.x - - go: 1.11.x - - go: 1.12.x - - go: 1.13.x - - go: tip - allow_failures: - - go: tip - -before_install: - - go get github.com/mitchellh/gox - -install: - - export GO111MODULE=on - - go get -t -v ./... - -script: - - go test -v -race ./... - - if [ "${LATEST}" = "true" ]; then gox -ldflags "-s -w" -os="linux darwin windows" -arch="386 amd64" -osarch="linux/arm" -output="pihole_exporter-{{.OS}}-{{.Arch}}" -verbose ./...; fi - -deploy: - provider: releases - skip_cleanup: true - api_key: - secure: $GITHUB_TOKEN - file: - - pihole_exporter-windows-386.exe - - pihole_exporter-windows-amd64.exe - - pihole_exporter-darwin-386 - - pihole_exporter-darwin-amd64 - - pihole_exporter-linux-386 - - pihole_exporter-linux-amd64 - - pihole_exporter-linux-arm - on: - repo: eko/pihole-exporter - tags: true - condition: $LATEST = true diff --git a/Dockerfile b/Dockerfile index 1b0115e..1207b0b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN apk update && \ RUN GO111MODULE=on go mod vendor RUN CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH go build -ldflags '-s -w' -o binary ./ -#RUN upx -f --brute binary +RUN upx -f --brute binary FROM $IMAGE