gorush/.github/workflows/build.yaml

95 lines
2.8 KiB
YAML

name: Docker Image
on:
push:
branches:
- master
tags:
- 'v*'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
max-parallel: 3
matrix:
os: [ubuntu-latest]
system: [linux]
arch: [amd64, arm, arm64]
# support windows build and push?
# see the issue: https://github.com/docker/build-push-action/issues/18
# include:
# - os: windows-2022
# system: windows
# arch: amd64
steps:
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: '^1'
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build binary
run : |
make build_${{ matrix.system }}_${{ matrix.arch }}
- name: Check binary
if: matrix.system == 'linux' && matrix.arch == 'amd64'
run : |
./release/${{ matrix.system }}/${{ matrix.arch }}/${GITHUB_REPOSITORY#*/} --help
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
-
name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Docker meta for ${{ matrix.system }} ${{ matrix.arch }}
id: docker-meta
uses: docker/metadata-action@v4
with:
flavor: |
latest=false
suffix=${{ matrix.system }}-${{ matrix.arch }}
images: |
${{ github.repository }}
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=,enable={{is_default_branch}}
type=raw,value=latest,suffix=,enable={{is_default_branch}}
type=semver,event=tag,pattern={{version}},suffix=-${{ matrix.system }}-${{ matrix.arch }}
type=semver,event=tag,pattern={{major}}.{{minor}},suffix=-${{ matrix.system }}-${{ matrix.arch }}
type=semver,event=tag,pattern={{major}},suffix=-${{ matrix.system }}-${{ matrix.arch }}
-
name: Build and push ${{ matrix.system }} ${{ matrix.arch }}
uses: docker/build-push-action@v3
with:
context: .
file: docker/Dockerfile.${{ matrix.system }}.${{ matrix.arch }}
platforms: ${{ matrix.system }}/${{ matrix.arch }}
push: true
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}