Skip to content

Commit 90c3b6e

Browse files
added Dockerfile and build workflow
1 parent 8584b1f commit 90c3b6e

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

.github/workflows/build.yaml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build and Push Public Image
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch:
7+
inputs:
8+
version_tag:
9+
description: 'Optional version tag (e.g. v1.0.0)'
10+
required: false
11+
type: string
12+
13+
jobs:
14+
build-and-push:
15+
runs-on: ubuntu-latest
16+
permissions:
17+
contents: read
18+
packages: write
19+
20+
steps:
21+
- uses: actions/checkout@v4
22+
23+
- name: Log in to GitHub Container Registry
24+
uses: docker/login-action@v3
25+
with:
26+
registry: ghcr.io
27+
username: ${{ github.actor }}
28+
password: ${{ secrets.GITHUB_TOKEN }}
29+
30+
- name: Set image names
31+
id: vars
32+
run: |
33+
IMAGE_BASE=ghcr.io/${{ github.repository_owner }}/k8s-restart
34+
echo "IMAGE_LATEST=$IMAGE_BASE:latest" >> $GITHUB_OUTPUT
35+
if [[ -n "${{ github.event.inputs.version_tag }}" ]]; then
36+
echo "IMAGE_VERSION=$IMAGE_BASE:${{ github.event.inputs.version_tag }}" >> $GITHUB_OUTPUT
37+
fi
38+
39+
- name: Build once and tag
40+
run: |
41+
docker build -t ${{ steps.vars.outputs.IMAGE_LATEST }} .
42+
if [ -n "${{ steps.vars.outputs.IMAGE_VERSION }}" ]; then
43+
docker tag ${{ steps.vars.outputs.IMAGE_LATEST }} ${{ steps.vars.outputs.IMAGE_VERSION }}
44+
fi
45+
46+
- name: Push all tags
47+
run: |
48+
docker push ${{ steps.vars.outputs.IMAGE_LATEST }}
49+
if [ -n "${{ steps.vars.outputs.IMAGE_VERSION }}" ]; then
50+
docker push ${{ steps.vars.outputs.IMAGE_VERSION }}
51+
fi

Doclerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# 🛠 Build stage
2+
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
3+
WORKDIR /src
4+
5+
# Copy and restore project
6+
COPY K8sControlApi.csproj ./
7+
RUN dotnet restore
8+
9+
# Copy the rest of the app
10+
COPY . ./
11+
RUN dotnet publish -c Release -o /app/publish
12+
13+
# 🚀 Runtime stage
14+
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
15+
WORKDIR /app
16+
COPY --from=build /app/publish .
17+
18+
# Expose HTTP port
19+
EXPOSE 80
20+
21+
# Entry point
22+
ENTRYPOINT ["dotnet", "K8sControlApi.dll"]

0 commit comments

Comments
 (0)