Skip to content

Commit

Permalink
chore(docker): support multiple platform
Browse files Browse the repository at this point in the history
fix #720
  • Loading branch information
appleboy committed Feb 27, 2023
1 parent a493ed6 commit f434c97
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 120 deletions.
51 changes: 17 additions & 34 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,13 @@ on:
- master
tags:
- 'v*'
pull_request:
branches:
- 'master'

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
build-docker:
runs-on: ubuntu-latest
steps:
- name: Setup go
uses: actions/setup-go@v3
Expand All @@ -34,13 +25,9 @@ jobs:

- 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
make build_linux_amd64
make build_linux_arm
make build_linux_arm64
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
Expand All @@ -65,30 +52,26 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

-
name: Docker meta for ${{ matrix.system }} ${{ matrix.arch }}
name: Docker meta
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 }}
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
-
name: Build and push ${{ matrix.system }} ${{ matrix.arch }}
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: docker/Dockerfile.${{ matrix.system }}.${{ matrix.arch }}
platforms: ${{ matrix.system }}/${{ matrix.arch }}
push: true
platforms: linux/amd64,linux/arm,linux/arm64
file: docker/Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.docker-meta.outputs.tags }}
labels: ${{ steps.docker-meta.outputs.labels }}
12 changes: 2 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ jobs:
args: --verbose

- uses: hadolint/hadolint-action@v3.1.0
name: hadolint for Dockerfile.linux.amd64
name: hadolint for Dockerfile
with:
dockerfile: docker/Dockerfile.linux.amd64
- uses: hadolint/hadolint-action@v3.1.0
name: hadolint for Dockerfile.linux.arm64
with:
dockerfile: docker/Dockerfile.linux.arm64
- uses: hadolint/hadolint-action@v3.1.0
name: hadolint for Dockerfile.linux.arm
with:
dockerfile: docker/Dockerfile.linux.arm
dockerfile: docker/Dockerfile

testing:
runs-on: ubuntu-latest
Expand Down
9 changes: 6 additions & 3 deletions docker/Dockerfile.linux.arm → docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
FROM alpine:3.15.4@sha256:a777c9c66ba177ccfea23f2a216ff6721e78a662cd17019488c417135299cd89
FROM alpine:3.17

ARG TARGETOS
ARG TARGETARCH

LABEL maintainer="Bo-Yi Wu <appleboy.tw@gmail.com>" \
org.label-schema.name="Gorush" \
org.label-schema.vendor="Bo-Yi Wu" \
org.label-schema.schema-version="1.0"

RUN apk add --no-cache ca-certificates mailcap && \
echo "@testing http://nl.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories
rm -rf /var/cache/apk/*

COPY release/linux/arm/gorush /bin/
COPY release/${TARGETOS}/${TARGETARCH}/gorush /bin/

EXPOSE 8088 9000
HEALTHCHECK --start-period=1s --interval=10s --timeout=5s \
Expand Down
17 changes: 0 additions & 17 deletions docker/Dockerfile.linux.amd64

This file was deleted.

17 changes: 0 additions & 17 deletions docker/Dockerfile.linux.arm64

This file was deleted.

14 changes: 0 additions & 14 deletions docker/Dockerfile.windows.amd64

This file was deleted.

25 changes: 0 additions & 25 deletions docker/manifest.tmpl

This file was deleted.

0 comments on commit f434c97

Please sign in to comment.