Skip to content

Commit 8970b01

Browse files
committed
try optimizing the build
1 parent 4a2e9e7 commit 8970b01

4 files changed

Lines changed: 68 additions & 23 deletions

File tree

.github/workflows/build-and-push.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,14 @@ on:
88

99
jobs:
1010
build-and-push:
11-
runs-on: ubuntu-latest
11+
runs-on: ubuntu-24.04-arm
1212
permissions:
1313
contents: read
1414
packages: write
1515

1616
steps:
1717
- uses: actions/checkout@v4
1818

19-
- name: Set up QEMU
20-
uses: docker/setup-qemu-action@v3
21-
2219
- name: Set up Docker Buildx
2320
uses: docker/setup-buildx-action@v3
2421

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Build and Push Base Image
2+
3+
on:
4+
push:
5+
paths:
6+
- 'HomeSpeaker.Server2/Dockerfile.base'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build-base:
11+
runs-on: ubuntu-24.04-arm
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Docker Buildx
20+
uses: docker/setup-buildx-action@v3
21+
22+
- name: Log in to GitHub Container Registry
23+
uses: docker/login-action@v3
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
29+
- name: Build and push base image
30+
uses: docker/build-push-action@v5
31+
with:
32+
context: .
33+
file: ./HomeSpeaker.Server2/Dockerfile.base
34+
platforms: linux/arm64
35+
push: true
36+
tags: ghcr.io/snow-jallen/homespeaker-base:latest
37+
cache-from: type=gha
38+
cache-to: type=gha,mode=max

HomeSpeaker.Server2/Dockerfile

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
# syntax=docker/dockerfile:1
2-
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
3-
4-
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base
5-
6-
# Install runtime dependencies in one layer with cleanup
7-
# --no-install-recommends: Don't install recommended packages (saves 100-200MB)
8-
# apt-get clean + rm: Remove apt cache (saves 50-100MB)
9-
RUN apt-get update \
10-
&& apt-get install -y --no-install-recommends \
11-
sox \
12-
libsox-fmt-mp3 \
13-
alsa-utils \
14-
vlc \
15-
ffmpeg \
16-
curl \
17-
iputils-ping \
18-
&& apt-get clean \
19-
&& rm -rf /var/lib/apt/lists/*
2+
# App image — builds on the pre-built base (ghcr.io/snow-jallen/homespeaker-base)
3+
# which contains all system packages (sox, ffmpeg, vlc, etc.).
4+
# Rebuild the base image via the build-base-image.yml workflow when packages change.
5+
6+
FROM ghcr.io/snow-jallen/homespeaker-base:latest AS base
207

218
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
229
CMD curl -f http://localhost:8080/health || exit 1
@@ -48,7 +35,6 @@ RUN --mount=type=cache,target=/root/.nuget/packages \
4835

4936
FROM base AS final
5037

51-
RUN grep 1000 /etc/passwd && usermod -aG audio ubuntu
5238
USER ubuntu
5339

5440
WORKDIR /app
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# syntax=docker/dockerfile:1
2+
# Base image with system-level dependencies that change infrequently.
3+
# Rebuild and push manually (or via build-base-image.yml workflow) when
4+
# packages need to be added/updated. The app image (Dockerfile) builds on top
5+
# of this, skipping the slow apt-get step on every push.
6+
7+
FROM mcr.microsoft.com/dotnet/aspnet:10.0
8+
9+
# Install runtime dependencies in one layer with cleanup
10+
# --no-install-recommends: Don't install recommended packages (saves 100-200MB)
11+
# apt-get clean + rm: Remove apt cache (saves 50-100MB)
12+
RUN apt-get update \
13+
&& apt-get install -y --no-install-recommends \
14+
sox \
15+
libsox-fmt-mp3 \
16+
alsa-utils \
17+
vlc \
18+
ffmpeg \
19+
curl \
20+
iputils-ping \
21+
&& apt-get clean \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
RUN grep 1000 /etc/passwd && usermod -aG audio ubuntu

0 commit comments

Comments
 (0)