feat: publish docker image in ci

master
Shengjing Zhu 2022-03-08 12:22:51 +08:00
parent ad658fd99d
commit f77617f529
3 changed files with 85 additions and 0 deletions

55
.github/workflows/ci.yaml vendored Normal file
View File

@ -0,0 +1,55 @@
name: ci
on:
push:
branches:
- "master"
tags:
- "v*"
pull_request:
branches:
- "master"
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: zhusj/wghttp,ghcr.io/zhsj/wghttp
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build
uses: docker/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file }}
targets: build
push: ${{ github.event_name != 'pull_request' }}

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM --platform=$BUILDPLATFORM golang as builder
WORKDIR /app
COPY . .
RUN go mod vendor
ARG TARGETARCH
RUN CGO_ENABLED=0 GOARCH=$TARGETARCH go build -v -trimpath -ldflags="-w -s" .
FROM scratch
COPY --from=builder /app/wghttp /
ENTRYPOINT ["/wghttp"]

20
docker-bake.hcl Normal file
View File

@ -0,0 +1,20 @@
target "docker-metadata-action" {}
target "build" {
inherits = ["docker-metadata-action"]
context = "./"
platforms = [
"linux/386",
"linux/amd64",
"linux/arm",
"linux/arm64",
"linux/mips",
"linux/mips64",
"linux/mips64le",
"linux/mipsle",
"linux/ppc64",
"linux/ppc64le",
"linux/riscv64",
"linux/s390x",
]
}