Skip to content

Commit

Permalink
feat: support to build and release mutiple arch images
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Jan 4, 2024
1 parent be5a4a3 commit 41f45e4
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 22 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,31 @@ jobs:
- uses: gaurav-nelson/github-action-markdown-link-check@1.0.13
with:
use-verbose-mode: 'yes'

image:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/linuxsuren/hd
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VERSION=${{ steps.vars.outputs.tag }}
35 changes: 35 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,41 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GH_PUBLISH_SECRETS }}

image:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-tags: true
fetch-depth: 0
- name: Setup Docker buildx
uses: docker/setup-buildx-action@79abd3f86f79a9d68a23c75a09a9a85889262adf
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@28218f9b04b4f3f62068d7b6ce6ca5b26e35336c
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GH_PUBLISH_SECRETS }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ env.REGISTRY }}/linuxsuren/hd
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: VERSION=${{ steps.vars.outputs.tag }}

msi:
needs: goreleaser
runs-on: windows-latest
Expand Down
16 changes: 0 additions & 16 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,3 @@ brews:
bin.install name
prefix.install_metafiles
dockers:
- goos: linux
goarch: amd64
image_templates:
- "surenpi/hd:latest"
- "surenpi/hd:{{.Tag}}"
- "ghcr.io/linuxsuren/hd:latest"
- "ghcr.io/linuxsuren/hd:{{.Tag}}"
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--label=org.opencontainers.image.source=https://github.com/LinuxSuRen/http-downloader"
- "--platform=linux/amd64"
15 changes: 14 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
FROM docker.io/golang:1.19 AS builder

WORKDIR /workspace
COPY cmd/ cmd/
COPY hack/ hack/
COPY mock/ mock/
COPY pkg/ pkg/
COPY main.go .
COPY README.md README.md
COPY go.mod go.mod
COPY go.sum go.sum
RUN CGO_ENABLED=0 go build -ldflags "-w -s" -o /usr/local/bin/hd .

FROM alpine:3.10

COPY hd /usr/local/bin/hd
COPY --from=builder /usr/local/bin/hd /usr/local/bin/hd
RUN hd fetch

CMD ["hd"]
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
build: fmt test
export GOPROXY=https://goproxy.io
CGO_ENABLE=0 go build -ldflags "-w -s" -o bin/hd
CGO_ENABLED=0 go build -ldflags "-w -s" -o bin/hd

build-windows:
GOOS=windows CGO_ENABLE=0 go build -ldflags "-w -s" -o bin/windows/hd.exe
GOOS=windows CGO_ENABLED=0 go build -ldflags "-w -s" -o bin/windows/hd.exe
build-linux: fmt lint build-linux-no-check
build-linux-no-check:
export GOPROXY=https://goproxy.io
CGO_ENABLE=0 GOOS=linux go build -ldflags "-w -s" -o bin/linux/hd
CGO_ENABLED=0 GOOS=linux go build -ldflags "-w -s" -o bin/linux/hd
upx bin/linux/hd

test: fmt
Expand Down
4 changes: 2 additions & 2 deletions pkg/installer/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,9 @@ func GetProxyServers() []string {

if err = yaml.Unmarshal(data, proxyServer); err == nil {
return proxyServer.Servers
} else {
log.Println("failed to parse config file", err)
}

log.Println("failed to parse config file", err)
} else {
log.Println("failed to read config file", err)
}
Expand Down

0 comments on commit 41f45e4

Please sign in to comment.