From d0ed2bb2fbd0e68efe8da3db2df142c0ae4b8566 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Mon, 27 Feb 2023 14:01:12 +0800 Subject: [PATCH] chore(docker): support multiple platform --- .github/workflows/docker.yml | 51 +++++++------------ .github/workflows/lint.yml | 12 +---- docker/{Dockerfile.linux.amd64 => Dockerfile} | 9 ++-- docker/Dockerfile.linux.arm | 13 ----- docker/Dockerfile.linux.arm64 | 13 ----- docker/Dockerfile.windows.amd64 | 9 ---- docker/manifest.tmpl | 25 --------- 7 files changed, 25 insertions(+), 107 deletions(-) rename docker/{Dockerfile.linux.amd64 => Dockerfile} (62%) delete mode 100644 docker/Dockerfile.linux.arm delete mode 100644 docker/Dockerfile.linux.arm64 delete mode 100644 docker/Dockerfile.windows.amd64 delete mode 100644 docker/manifest.tmpl diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 5e18bd7..f9e3532 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 @@ -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 @@ -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=${{ matrix.system == 'linux' && matrix.arch == 'amd64' }} - 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 }} diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 32c7bee..dfda69a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -21,17 +21,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 diff --git a/docker/Dockerfile.linux.amd64 b/docker/Dockerfile similarity index 62% rename from docker/Dockerfile.linux.amd64 rename to docker/Dockerfile index 17107bc..ab1fd34 100644 --- a/docker/Dockerfile.linux.amd64 +++ b/docker/Dockerfile @@ -1,13 +1,16 @@ -FROM plugins/base:linux-amd64 +FROM alpine:3.17 + +ARG TARGETOS +ARG TARGETARCH LABEL maintainer="Bo-Yi Wu " \ - org.label-schema.name="Drone SSH" \ + org.label-schema.name="SSH Plugin" \ org.label-schema.vendor="Bo-Yi Wu" \ org.label-schema.schema-version="1.0" RUN apk add --no-cache ca-certificates && \ rm -rf /var/cache/apk/* -COPY release/linux/amd64/drone-ssh /bin/ +COPY release/${TARGETOS}/${TARGETARCH}/drone-ssh /bin/ ENTRYPOINT ["/bin/drone-ssh"] diff --git a/docker/Dockerfile.linux.arm b/docker/Dockerfile.linux.arm deleted file mode 100644 index 019c71b..0000000 --- a/docker/Dockerfile.linux.arm +++ /dev/null @@ -1,13 +0,0 @@ -FROM plugins/base:linux-arm - -LABEL maintainer="Bo-Yi Wu " \ - org.label-schema.name="Drone SSH" \ - org.label-schema.vendor="Bo-Yi Wu" \ - org.label-schema.schema-version="1.0" - -RUN apk add --no-cache ca-certificates && \ - rm -rf /var/cache/apk/* - -COPY release/linux/arm/drone-ssh /bin/ - -ENTRYPOINT ["/bin/drone-ssh"] diff --git a/docker/Dockerfile.linux.arm64 b/docker/Dockerfile.linux.arm64 deleted file mode 100644 index 14bc3d1..0000000 --- a/docker/Dockerfile.linux.arm64 +++ /dev/null @@ -1,13 +0,0 @@ -FROM plugins/base:linux-arm64 - -LABEL maintainer="Bo-Yi Wu " \ - org.label-schema.name="Drone SSH" \ - org.label-schema.vendor="Bo-Yi Wu" \ - org.label-schema.schema-version="1.0" - -RUN apk add --no-cache ca-certificates && \ - rm -rf /var/cache/apk/* - -COPY release/linux/arm64/drone-ssh /bin/ - -ENTRYPOINT ["/bin/drone-ssh"] diff --git a/docker/Dockerfile.windows.amd64 b/docker/Dockerfile.windows.amd64 deleted file mode 100644 index c603143..0000000 --- a/docker/Dockerfile.windows.amd64 +++ /dev/null @@ -1,9 +0,0 @@ -FROM microsoft/nanoserver:10.0.14393.1884 - -LABEL maintainer="Bo-Yi Wu " \ - org.label-schema.name="Drone SSH" \ - org.label-schema.vendor="Bo-Yi Wu" \ - org.label-schema.schema-version="1.0" - -ADD drone-ssh.exe /drone-ssh.exe -ENTRYPOINT [ "\\drone-ssh.exe" ] diff --git a/docker/manifest.tmpl b/docker/manifest.tmpl deleted file mode 100644 index 5aff9af..0000000 --- a/docker/manifest.tmpl +++ /dev/null @@ -1,25 +0,0 @@ -image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}} -{{#if build.tags}} -tags: -{{#each build.tags}} - - {{this}} -{{/each}} -{{/if}} -manifests: - - - image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64 - platform: - architecture: amd64 - os: linux - - - image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64 - platform: - architecture: arm64 - os: linux - variant: v8 - - - image: appleboy/drone-ssh:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm - platform: - architecture: arm - os: linux - variant: v7