Build: Improve speed and build a manifest for both architectures (#49)

This commit is contained in:
Gervasio Marchand 2024-01-03 21:04:11 -03:00 committed by GitHub
parent cbc49531ad
commit 91a2e5ebae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 28 deletions

View File

@ -32,9 +32,4 @@ jobs:
- name: Build things - name: Build things
shell: pwsh shell: pwsh
run: | run: |
if ('${{ matrix.architecture }}' -eq 'arm64v8') {
sudo apt-get install qemu binfmt-support qemu-user-static
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
sed -i 's/8.0.100-1-alpine3.18/8.0.100-alpine3.18/' Dockerfile
}
docker build . --build-arg ARCH=${{ matrix.architecture }} docker build . --build-arg ARCH=${{ matrix.architecture }}

View File

@ -78,9 +78,6 @@ jobs:
create-docker-image: create-docker-image:
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [ create-release ] needs: [ create-release ]
strategy:
matrix:
architecture: [ amd64, arm64v8 ]
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v3
@ -94,19 +91,23 @@ jobs:
shell: pwsh shell: pwsh
run: | run: |
$version = '${{ github.event.ref }}'.Replace('refs/tags/', '').Replace('v', '') $version = '${{ github.event.ref }}'.Replace('refs/tags/', '').Replace('v', '')
$packageUrl = "ghcr.io/${{ github.actor }}/${{ github.event.repository.name }}".ToLower()
if ('${{ matrix.architecture }}' -eq 'arm64v8') { $archs = "amd64", "arm64v8"
sudo apt-get install qemu binfmt-support qemu-user-static foreach ($arch in $archs) {
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes docker build -t "$($packageUrl):latest-$($arch)" --build-arg ARCH=$($arch) .
sed -i 's/8.0.100-1-alpine3.18/8.0.100-alpine3.18/' Dockerfile docker tag "$($packageUrl):latest-$($arch)" "$($packageUrl):$($version)-$($arch)"
docker push "$($packageUrl):latest-$($arch)"
docker push "$($packageUrl):$($version)-$($arch)"
} }
docker build . -t ghcr.io/g3rv4/getmoarfediverse:latest-${{ matrix.architecture }} --build-arg ARCH=${{ matrix.architecture }} docker manifest create `
docker tag ghcr.io/g3rv4/getmoarfediverse:latest-${{ matrix.architecture }} ghcr.io/g3rv4/getmoarfediverse:$version-${{ matrix.architecture }} "$($packageUrl):latest" `
docker push ghcr.io/g3rv4/getmoarfediverse:latest-${{ matrix.architecture }} --amend "$($packageUrl):latest-amd64" `
docker push ghcr.io/g3rv4/getmoarfediverse:$version-${{ matrix.architecture }} --amend "$($packageUrl):latest-arm64v8"
docker manifest create `
if ('${{ matrix.architecture }}' -eq 'amd64') { "$($packageUrl):$($version)" `
docker tag ghcr.io/g3rv4/getmoarfediverse:latest-${{ matrix.architecture }} ghcr.io/g3rv4/getmoarfediverse:latest --amend "$($packageUrl):$($version)-amd64" `
docker push ghcr.io/g3rv4/getmoarfediverse:latest --amend "$($packageUrl):$($version)-arm64v8"
} docker manifest push "$($packageUrl):latest"
docker manifest push "$($packageUrl):$($version)"

View File

@ -1,14 +1,11 @@
# syntax=docker/dockerfile:1
ARG ARCH= ARG ARCH=
FROM mcr.microsoft.com/dotnet/sdk:8.0.100-1-alpine3.18-${ARCH} AS builder FROM mcr.microsoft.com/dotnet/sdk:8.0.100-1-alpine3.18 AS builder
WORKDIR /src WORKDIR /src
COPY src /src/ COPY src /src/
RUN dotnet restore /src/GetMoarFediverse.csproj --disable-parallel RUN dotnet publish -c Release /src/GetMoarFediverse.csproj -o /app
RUN dotnet publish -c Release /src/GetMoarFediverse.csproj -o /app --no-restore
FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-alpine3.18-${ARCH} FROM mcr.microsoft.com/dotnet/aspnet:8.0.0-alpine3.18-${ARCH}
VOLUME ["/data"] WORKDIR /app
ENV CONFIG_PATH=/data/config.json ENV CONFIG_PATH=/data/config.json
COPY --from=builder /app /app COPY --from=builder /app /app
CMD ["/app/GetMoarFediverse"] CMD /usr/bin/dotnet GetMoarFediverse.dll