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
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
with:
|
|
||||||
image: tonistiigi/binfmt:latest
|
|
||||||
platforms: all
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
|
||||||
install: true
|
|
||||||
version: latest
|
|
||||||
driver-opts: image=moby/buildkit:master
|
|
||||||
- name: Login into DockerHub
|
- name: Login into DockerHub
|
||||||
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||||
- name: Login into GitHub Container Registry
|
- name: Login into GitHub Container Registry
|
||||||
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
||||||
|
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/${{ github.repository }}:${{ github.event.inputs.tag }}
|
ghcr.io/${{ github.repository }}:${{ github.event.inputs.tag }}
|
||||||
|
|||||||
@@ -22,16 +22,12 @@ jobs:
|
|||||||
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Setup Go
|
- name: Setup Golang with cache
|
||||||
uses: actions/setup-go@v4
|
uses: magnetikonline/action-golang-cache@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
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
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@v8
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
@@ -39,21 +35,15 @@ jobs:
|
|||||||
version: v2.4.0
|
version: v2.4.0
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test ./...
|
run: go test ./...
|
||||||
build-release:
|
build-docker:
|
||||||
name: Build and release Docker image
|
name: Build and release Docker image
|
||||||
needs: [check-date, test]
|
needs: [check-date, test]
|
||||||
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
if: ${{ needs.check-date.outputs.should_run == 'true' }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
with:
|
|
||||||
image: tonistiigi/binfmt:latest
|
|
||||||
platforms: all
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
with:
|
||||||
install: true
|
install: true
|
||||||
@@ -68,11 +58,11 @@ jobs:
|
|||||||
_short_hash=${{ github.sha }}
|
_short_hash=${{ github.sha }}
|
||||||
echo "SHORT_HASH=${_short_hash:0:7}" >> $GITHUB_ENV
|
echo "SHORT_HASH=${_short_hash:0:7}" >> $GITHUB_ENV
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
platforms: linux/amd64,linux/arm64,linux/arm/v7
|
platforms: linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
ghcr.io/${{ github.repository }}:${{ env.SHORT_HASH }}
|
ghcr.io/${{ github.repository }}:${{ env.SHORT_HASH }}
|
||||||
|
|||||||
@@ -8,16 +8,12 @@ jobs:
|
|||||||
name: Lint and test
|
name: Lint and test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Setup Go
|
- name: Setup Golang with cache
|
||||||
uses: actions/setup-go@v4
|
uses: magnetikonline/action-golang-cache@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
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
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@v8
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
@@ -43,32 +39,61 @@ jobs:
|
|||||||
release-type: simple
|
release-type: simple
|
||||||
changelog-path: CHANGELOG.md
|
changelog-path: CHANGELOG.md
|
||||||
package-name: gonic
|
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
|
name: Build, tag, and publish Docker image
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: [release-please]
|
needs: [release-please]
|
||||||
if: ${{ needs.release-please.outputs.release_created }}
|
if: ${{ needs.release-please.outputs.release_created }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
with:
|
|
||||||
image: tonistiigi/binfmt:latest
|
|
||||||
platforms: all
|
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
id: buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
uses: docker/setup-buildx-action@v1
|
||||||
with:
|
|
||||||
install: true
|
|
||||||
version: latest
|
|
||||||
driver-opts: image=moby/buildkit:master
|
|
||||||
- name: Login into DockerHub
|
- name: Login into DockerHub
|
||||||
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
run: echo ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||||
- name: Login into GitHub Container Registry
|
- name: Login into GitHub Container Registry
|
||||||
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
run: echo ${{ secrets.CR_PAT }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
|
||||||
- name: Build and Push
|
- name: Build and Push
|
||||||
uses: docker/build-push-action@v2
|
uses: docker/build-push-action@v6
|
||||||
with:
|
with:
|
||||||
context: .
|
context: .
|
||||||
file: ./Dockerfile
|
file: ./Dockerfile
|
||||||
@@ -79,6 +104,8 @@ jobs:
|
|||||||
ghcr.io/${{ github.repository }}:latest
|
ghcr.io/${{ github.repository }}:latest
|
||||||
${{ github.repository }}:${{ needs.release-please.outputs.tag_name }}
|
${{ github.repository }}:${{ needs.release-please.outputs.tag_name }}
|
||||||
${{ github.repository }}:latest
|
${{ github.repository }}:latest
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
notify-irc:
|
notify-irc:
|
||||||
needs: [release-please]
|
needs: [release-please]
|
||||||
name: Notify IRC
|
name: Notify IRC
|
||||||
|
|||||||
@@ -9,16 +9,12 @@ jobs:
|
|||||||
name: Lint and test
|
name: Lint and test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v4
|
||||||
- name: Setup Go
|
- name: Setup Golang with cache
|
||||||
uses: actions/setup-go@v4
|
uses: magnetikonline/action-golang-cache@v5
|
||||||
with:
|
with:
|
||||||
go-version-file: go.mod
|
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
|
- name: Lint
|
||||||
uses: golangci/golangci-lint-action@v8
|
uses: golangci/golangci-lint-action@v8
|
||||||
with:
|
with:
|
||||||
|
|||||||
+9
-20
@@ -1,19 +1,16 @@
|
|||||||
FROM golang:1.25-alpine3.22 AS builder
|
# syntax=docker/dockerfile:1
|
||||||
RUN apk add -U --no-cache \
|
FROM --platform=$BUILDPLATFORM golang:1.25-alpine3.22 AS builder
|
||||||
build-base \
|
ARG TARGETOS
|
||||||
ca-certificates \
|
ARG TARGETARCH
|
||||||
git \
|
|
||||||
sqlite \
|
|
||||||
zlib-dev \
|
|
||||||
taglib-dev \
|
|
||||||
go
|
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY go.mod .
|
COPY go.mod .
|
||||||
COPY go.sum .
|
COPY go.sum .
|
||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY . .
|
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
|
FROM alpine:3.22
|
||||||
LABEL org.opencontainers.image.source=https://github.com/sentriz/gonic
|
LABEL org.opencontainers.image.source=https://github.com/sentriz/gonic
|
||||||
@@ -24,15 +21,7 @@ RUN apk add -U --no-cache \
|
|||||||
tzdata \
|
tzdata \
|
||||||
tini \
|
tini \
|
||||||
shared-mime-info
|
shared-mime-info
|
||||||
|
COPY --from=builder /out/* /usr/local/bin/
|
||||||
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/
|
|
||||||
VOLUME ["/cache", "/data", "/music", "/podcasts"]
|
VOLUME ["/cache", "/data", "/music", "/podcasts"]
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
ENV TZ=
|
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