feat(ci): remove Cgo dependencies, cross compile without QEMU, upload static binaries
This commit is contained in:
No files matched your search
@@ -11,29 +11,19 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
image: tonistiigi/binfmt:latest
|
||||
platforms: all
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
install: true
|
||||
version: latest
|
||||
driver-opts: image=moby/buildkit:master
|
||||
- name: Login into DockerHub
|
||||
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
- name: Login into GitHub Container Registry
|
||||
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v2
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/${{ github.repository }}:${{ github.event.inputs.tag }}
|
||||
|
||||
@@ -22,16 +22,12 @@ jobs:
|
||||
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Golang with cache
|
||||
uses: magnetikonline/action-golang-cache@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update -qq
|
||||
sudo apt install -y -qq build-essential git sqlite3 libtag1-dev ffmpeg mpv zlib1g-dev
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
@@ -39,21 +35,15 @@ jobs:
|
||||
version: v2.4.0
|
||||
- name: Test
|
||||
run: go test ./...
|
||||
build-release:
|
||||
build-docker:
|
||||
name: Build and release Docker image
|
||||
needs: [check-date, test]
|
||||
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
image: tonistiigi/binfmt:latest
|
||||
platforms: all
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
install: true
|
||||
@@ -68,11 +58,11 @@ jobs:
|
||||
_short_hash=${{ github.sha }}
|
||||
echo "SHORT_HASH=${_short_hash:0:7}" >> $GITHUB_ENV
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v2
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||
push: true
|
||||
tags: |
|
||||
ghcr.io/${{ github.repository }}:${{ env.SHORT_HASH }}
|
||||
|
||||
@@ -8,16 +8,12 @@ jobs:
|
||||
name: Lint and test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Golang with cache
|
||||
uses: magnetikonline/action-golang-cache@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update -qq
|
||||
sudo apt install -y -qq build-essential git sqlite3 libtag1-dev ffmpeg mpv zlib1g-dev
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
@@ -43,32 +39,61 @@ jobs:
|
||||
release-type: simple
|
||||
changelog-path: CHANGELOG.md
|
||||
package-name: gonic
|
||||
build-release:
|
||||
build-binaries:
|
||||
name: Build binaries
|
||||
runs-on: ubuntu-latest
|
||||
needs: [release-please]
|
||||
if: ${{ needs.release-please.outputs.release_created }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [linux, windows, darwin]
|
||||
arch: [amd64, arm64, 386]
|
||||
exclude:
|
||||
- os: darwin
|
||||
arch: 386
|
||||
# https://github.com/natefinch/npipe/issues/33 (required by mpvipc)
|
||||
- os: windows
|
||||
arch: arm64
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Golang with cache
|
||||
uses: magnetikonline/action-golang-cache@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: Build
|
||||
run: |
|
||||
set -e
|
||||
CGO_ENABLED=0 GOOS="${{ matrix.os }}" GOARCH="${{ matrix.arch }}" go build -o out/ ./cmd/...
|
||||
[[ "${{ matrix.os }}" = "windows" ]] && suff=".exe"
|
||||
cd out/
|
||||
for p in *; do
|
||||
mv "$p" "${p%.*}-${{ matrix.os }}-${{ matrix.arch }}-${{ needs.release-please.outputs.tag_name }}$suff"
|
||||
done
|
||||
cd -
|
||||
- name: Upload
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.CR_PAT }}
|
||||
file: out/*
|
||||
file_glob: true
|
||||
tag: ${{ needs.release-please.outputs.tag_name }}
|
||||
build-docker:
|
||||
name: Build, tag, and publish Docker image
|
||||
runs-on: ubuntu-latest
|
||||
needs: [release-please]
|
||||
if: ${{ needs.release-please.outputs.release_created }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
with:
|
||||
image: tonistiigi/binfmt:latest
|
||||
platforms: all
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
with:
|
||||
install: true
|
||||
version: latest
|
||||
driver-opts: image=moby/buildkit:master
|
||||
- name: Login into DockerHub
|
||||
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
- name: Login into GitHub Container Registry
|
||||
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||
- name: Build and Push
|
||||
uses: docker/build-push-action@v2
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
@@ -79,6 +104,8 @@ jobs:
|
||||
ghcr.io/${{ github.repository }}:latest
|
||||
${{ github.repository }}:${{ needs.release-please.outputs.tag_name }}
|
||||
${{ github.repository }}:latest
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
notify-irc:
|
||||
needs: [release-please]
|
||||
name: Notify IRC
|
||||
|
||||
@@ -9,16 +9,12 @@ jobs:
|
||||
name: Lint and test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
- name: Setup Go
|
||||
uses: actions/setup-go@v4
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
- name: Setup Golang with cache
|
||||
uses: magnetikonline/action-golang-cache@v5
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt update -qq
|
||||
sudo apt install -y -qq build-essential git sqlite3 libtag1-dev ffmpeg mpv zlib1g-dev
|
||||
- name: Lint
|
||||
uses: golangci/golangci-lint-action@v8
|
||||
with:
|
||||
|
||||
+9
-20
@@ -1,19 +1,16 @@
|
||||
FROM golang:1.25-alpine3.22 AS builder
|
||||
RUN apk add -U --no-cache \
|
||||
build-base \
|
||||
ca-certificates \
|
||||
git \
|
||||
sqlite \
|
||||
zlib-dev \
|
||||
taglib-dev \
|
||||
go
|
||||
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM --platform=$BUILDPLATFORM golang:1.25-alpine3.22 AS builder
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
WORKDIR /src
|
||||
COPY go.mod .
|
||||
COPY go.sum .
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
RUN GOOS=linux go build -o gonic cmd/gonic/gonic.go
|
||||
RUN \
|
||||
--mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH go build -o /out/ ./cmd/...
|
||||
|
||||
FROM alpine:3.22
|
||||
LABEL org.opencontainers.image.source=https://github.com/sentriz/gonic
|
||||
@@ -24,15 +21,7 @@ RUN apk add -U --no-cache \
|
||||
tzdata \
|
||||
tini \
|
||||
shared-mime-info
|
||||
|
||||
COPY --from=builder \
|
||||
/usr/lib/libgcc_s.so.1 \
|
||||
/usr/lib/libstdc++.so.6 \
|
||||
/usr/lib/libtag.so.2 \
|
||||
/usr/lib/
|
||||
COPY --from=builder \
|
||||
/src/gonic \
|
||||
/bin/
|
||||
COPY --from=builder /out/* /usr/local/bin/
|
||||
VOLUME ["/cache", "/data", "/music", "/podcasts"]
|
||||
EXPOSE 80
|
||||
ENV TZ=
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
FROM golang:1.24-alpine3.22 AS builder
|
||||
RUN apk add -U --no-cache \
|
||||
build-base \
|
||||
ca-certificates \
|
||||
git \
|
||||
sqlite \
|
||||
taglib-dev \
|
||||
zlib-dev \
|
||||
shared-mime-info
|
||||
WORKDIR /src
|
||||
@@ -1,39 +0,0 @@
|
||||
# syntax=docker/dockerfile:experimental
|
||||
|
||||
FROM golang:1.24-alpine3.22 AS builder
|
||||
RUN apk add -U --no-cache \
|
||||
build-base \
|
||||
ca-certificates \
|
||||
git \
|
||||
sqlite \
|
||||
taglib-dev \
|
||||
zlib-dev
|
||||
WORKDIR /src
|
||||
COPY . .
|
||||
RUN --mount=type=cache,target=/go/pkg/mod \
|
||||
--mount=type=cache,target=/root/.cache/go-build \
|
||||
GOOS=linux go build -o gonic cmd/gonic/gonic.go
|
||||
|
||||
FROM alpine:3.22
|
||||
RUN apk add -U --no-cache \
|
||||
ffmpeg \
|
||||
mpv \
|
||||
ca-certificates \
|
||||
shared-mime-info
|
||||
COPY --from=builder \
|
||||
/usr/lib/libgcc_s.so.1 \
|
||||
/usr/lib/libstdc++.so.6 \
|
||||
/usr/lib/libtag.so.1 \
|
||||
/usr/lib/
|
||||
COPY --from=builder \
|
||||
/src/gonic \
|
||||
/bin/
|
||||
VOLUME ["/cache", "/data", "/music", "/podcasts"]
|
||||
EXPOSE 80
|
||||
ENV GONIC_DB_PATH=/data/gonic.db
|
||||
ENV GONIC_LISTEN_ADDR=:80
|
||||
ENV GONIC_MUSIC_PATH=/music
|
||||
ENV GONIC_PODCAST_PATH=/podcasts
|
||||
ENV GONIC_PLAYLISTS_PATH=/playlists
|
||||
ENV GONIC_CACHE_PATH=/cache
|
||||
CMD ["gonic"]
|
||||
Reference in New Issue
Block a user