Skip to content

Commit 2148d93

Browse files
authored
Merge pull request bdovaz#181 from Nefelim4ag/master
feat(github-ci): add docker image build
2 parents 227b964 + 8cfed8b commit 2148d93

2 files changed

Lines changed: 54 additions & 3 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Build docker image
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
env:
9+
PROJECT_NAME: UnityNuGet
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
build-image:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- name: Checkout repository
22+
uses: actions/checkout@v3
23+
24+
- name: Set up QEMU
25+
uses: docker/setup-qemu-action@v2
26+
27+
- name: Set up Docker Buildx
28+
uses: docker/setup-buildx-action@v2
29+
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v2
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@v4
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
43+
- name: Build and push Docker image
44+
uses: docker/build-push-action@v4
45+
with:
46+
context: .
47+
push: true
48+
platforms: linux/amd64,linux/arm64
49+
tags: ${{ steps.meta.outputs.tags }}
50+
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:7.0.100 AS build
1+
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:7.0 AS build
2+
ARG TARGETARCH
23
WORKDIR /app
34

45
RUN mkdir -p src/UnityNuGet && mkdir -p src/UnityNuGet.Server && mkdir -p src/UnityNuGet.Tests
@@ -7,10 +8,10 @@ COPY src/*.sln src
78
COPY src/UnityNuGet/*.csproj src/UnityNuGet
89
COPY src/UnityNuGet.Server/*.csproj src/UnityNuGet.Server
910
COPY src/UnityNuGet.Tests/*.csproj src/UnityNuGet.Tests
10-
RUN dotnet restore src
11+
RUN dotnet restore src -a $TARGETARCH
1112

1213
COPY . ./
13-
RUN dotnet publish src -c Release -o /app/src/out
14+
RUN dotnet publish src -a $TARGETARCH -c Release -o /app/src/out
1415

1516
# Build runtime image
1617
FROM mcr.microsoft.com/dotnet/aspnet:7.0

0 commit comments

Comments
 (0)