Skip to content

Commit 2ec7994

Browse files
committed
chore: add Docker image
See #156, thanks @odiroot
1 parent 4952771 commit 2ec7994

File tree

4 files changed

+111
-0
lines changed

4 files changed

+111
-0
lines changed

.github/workflows/docker.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Publish Docker image
2+
3+
on:
4+
push:
5+
tags: [ 'v*' ]
6+
branches: [ "master" ]
7+
pull_request:
8+
branches: [ 'master' ]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
packages: write
20+
id-token: write
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
# Install the cosign tool except on PR
27+
- name: Install cosign
28+
if: github.event_name != 'pull_request'
29+
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0
30+
with:
31+
cosign-release: 'v2.2.4'
32+
33+
# Set up BuildKit Docker container builder to be able to build
34+
# multi-platform images and export cache
35+
- name: Set up Docker Buildx
36+
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0
37+
38+
# Login against a Docker registry except on PR
39+
- name: Log into registry ${{ env.REGISTRY }}
40+
if: github.event_name != 'pull_request'
41+
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
42+
with:
43+
registry: ${{ env.REGISTRY }}
44+
username: ${{ github.actor }}
45+
password: ${{ secrets.GITHUB_TOKEN }}
46+
47+
# Extract metadata (tags, labels) for Docker
48+
- name: Extract Docker metadata
49+
id: meta
50+
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
51+
with:
52+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
53+
54+
# Build and push Docker image with Buildx (don't push on PR)
55+
- name: Build and push Docker image
56+
id: build-and-push
57+
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0
58+
with:
59+
context: .
60+
push: ${{ github.event_name != 'pull_request' }}
61+
tags: ${{ steps.meta.outputs.tags }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
cache-from: type=gha
64+
cache-to: type=gha,mode=max
65+
66+
# Sign the resulting Docker image digest except on PRs.
67+
- name: Sign the published Docker image
68+
if: ${{ github.event_name != 'pull_request' }}
69+
env:
70+
TAGS: ${{ steps.meta.outputs.tags }}
71+
DIGEST: ${{ steps.build-and-push.outputs.digest }}
72+
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM alpine:3.20 AS build
2+
3+
RUN apk -U --no-cache add go alsa-lib-dev libogg-dev libvorbis-dev
4+
5+
WORKDIR /src
6+
7+
COPY go.mod go.sum ./
8+
RUN go mod download
9+
10+
COPY . .
11+
RUN go build -v ./cmd/daemon
12+
13+
FROM alpine:3.20
14+
15+
RUN apk -U --no-cache add libpulse avahi libgcc gcompat alsa-lib
16+
17+
COPY --from=build /src/daemon /usr/bin/go-librespot
18+
19+
CMD ["/usr/bin/go-librespot", "--config_dir", "/config"]

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ the [latest release](https://github.com/devgianlu/go-librespot/releases/latest).
1919
Development prebuilt binaries are also available
2020
as [GitHub Actions artifacts](https://github.com/devgianlu/go-librespot/blob/249b8fee709e2d08fe9c39a16ad0fc4b737cb967/.github/workflows/release.yml#L62).
2121

22+
### Using Docker
23+
24+
A lightweight Docker image for go-librespot is available
25+
on the [GitHub Container Registry](https://github.com/devgianlu/go-fileshare/pkgs/container/go-fileshare).
26+
27+
An example Docker Compose configuration for PulseAudio is available [here](/docker-compose.pulse.yml).
28+
2229
### Building from source
2330

2431
To build from source the following prerequisites are necessary:

docker-compose.pulse.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
daemon:
3+
image: ghcr.io/devgianlu/go-librespot
4+
build: .
5+
network_mode: host
6+
userns_mode: keep-id
7+
volumes:
8+
- ~/.config/go-librespot:/config
9+
- ~/.config/pulse/cookie:/pulse_cookie:ro
10+
- /run/user/1000/pulse/native:/pulse_native # Replace 1000 with your UID
11+
environment:
12+
PULSE_SERVER: "unix:/pulse_native"
13+
PULSE_COOKIE: "/pulse_cookie"

0 commit comments

Comments
 (0)