build: create amd64/arm64 compatible docker images (#23)

This commit is contained in:
l3uddz
2021-02-22 18:24:11 +00:00
committed by GitHub
parent 10a70f1da2
commit 7472fcbf0c
3 changed files with 76 additions and 42 deletions

View File

@@ -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

View File

@@ -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 }}

View File

@@ -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"]