diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7950fea..d500e7b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,10 +12,16 @@ jobs: runs-on: ubuntu-latest steps: # dependencies - - name: dependencies + - name: goreleaser run: | curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sudo sh -s -- -b /usr/local/bin + - name: qemu + uses: docker/setup-qemu-action@v1 + + - name: buildx + uses: docker/setup-buildx-action@v1 + # checkout - name: checkout uses: actions/checkout@v2 @@ -27,8 +33,11 @@ jobs: uses: actions/setup-go@v1 with: go-version: 1.16 - - run: go version - - run: go env + + - name: go info + run: | + go version + go env # cache - name: cache @@ -50,7 +59,8 @@ jobs: make test # git status - - run: git status + - name: git status + run: git status # build - name: build @@ -86,43 +96,64 @@ jobs: name: build_windows path: dist/*windows* - # docker build (latest & tag) - - name: docker - build latest - if: startsWith(github.ref, 'refs/tags/') == true - uses: docker/build-push-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: cloudb0x/nabarr - dockerfile: docker/Dockerfile - tags: latest - tag_with_ref: true - tag_with_sha: false - always_pull: true + # docker login + - name: docker login + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | + echo "${DOCKER_PASSWORD}" | docker login --username "${DOCKER_USERNAME}" --password-stdin - # docker build (master) - - name: docker - build master - if: github.ref == 'refs/heads/master' - uses: docker/build-push-action@v1 + # docker build (latest & tag) + - name: release tag + if: startsWith(github.ref, 'refs/tags/') == true + uses: little-core-labs/get-git-tag@v3.0.2 + id: releasetag with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: cloudb0x/nabarr - dockerfile: docker/Dockerfile - tags: master - tag_with_ref: false - tag_with_sha: false - always_pull: true + tagRegex: "v?(.+)" + + - name: docker - build release + if: startsWith(github.ref, 'refs/tags/') == true + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/amd64,linux/arm64 + pull: true + push: true + tags: | + cloudb0x/nabarr:${{ steps.releasetag.outputs.tag }} + cloudb0x/nabarr:latest # docker build (branch) - - name: docker - build other - if: startsWith(github.ref, 'refs/heads/master') == false - uses: docker/build-push-action@v1 + - name: branch name + if: startsWith(github.ref, 'refs/tags/') == false + id: branch-name + uses: tj-actions/branch-names@v2.2 + + - name: docker tag + if: startsWith(github.ref, 'refs/tags/') == false + uses: frabert/replace-string-action@master + id: dockertag with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: cloudb0x/nabarr - dockerfile: docker/Dockerfile - tag_with_ref: true - tag_with_sha: false - always_pull: true + pattern: '[:\.\/]+' + string: "${{ steps.branch-name.outputs.current_branch }}" + replace-with: '-' + flags: 'g' + + - name: docker - build branch + if: startsWith(github.ref, 'refs/tags/') == false + uses: docker/build-push-action@v2 + with: + context: . + file: ./docker/Dockerfile + platforms: linux/amd64,linux/arm64 + pull: true + push: true + tags: | + cloudb0x/nabarr:${{ steps.dockertag.outputs.replaced }} + + # cleanup + - name: cleanup + run: | + rm -f ${HOME}/.docker/config.json \ No newline at end of file diff --git a/.github/workflows/cleanup.yml b/.github/workflows/cleanup.yml index 84a0ebc..1980bee 100644 --- a/.github/workflows/cleanup.yml +++ b/.github/workflows/cleanup.yml @@ -7,7 +7,7 @@ jobs: if: startsWith(github.event.ref_type, 'branch') == true runs-on: ubuntu-latest steps: - - name: Sanitize branch docker tag + - name: docker tag uses: frabert/replace-string-action@master id: dockertag with: @@ -16,7 +16,7 @@ jobs: replace-with: '-' flags: 'g' - - name: Remove branch docker tag + - name: remove docker tag shell: bash env: username: ${{ secrets.DOCKER_USERNAME }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 8043aea..7ed54f6 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,5 +1,8 @@ FROM sc4h/alpine-s6overlay:3.12 +ARG TARGETOS +ARG TARGETARCH + ENV \ PATH="/app/nabarr:${PATH}" \ APP_CONFIG="/config/config.yml" \ @@ -8,7 +11,7 @@ ENV \ APP_VERBOSITY="0" # Binary -COPY ["dist/nabarr_linux_amd64/nabarr", "/app/nabarr/nabarr"] +COPY ["dist/nabarr_${TARGETOS}_${TARGETARCH}/nabarr", "/app/nabarr/nabarr"] # Add root files COPY ["docker/run", "/etc/services.d/nabarr/run"]