feat: publish docker image in ci
parent
ad658fd99d
commit
f77617f529
|
|
@ -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' }}
|
||||
|
|
@ -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"]
|
||||
|
|
@ -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",
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue