Merge branch 'Workflow' into master

This commit is contained in:
Tech Garage 2024-09-27 23:53:11 +03:30 committed by GitHub
commit 7d4a6e1864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 45 additions and 53 deletions

View file

@ -13,7 +13,7 @@ on:
tag:
required: true
description: 'Output image tag'
jobs:
build-and-push:
runs-on: ubuntu-latest
@ -41,17 +41,50 @@ jobs:
username: ${{ github.repository_owner }}
password: ${{ secrets.GHCR_PAT }}
- name: Install .NET SDK
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
- name: Set Runtime Identifier
id: set_rid
run: |
if [[ "$RUNNER_ARCH" == "X64" ]]; then
echo "RID=linux-x64" >> $GITHUB_ENV
else
echo "RID=linux-arm64" >> $GITHUB_ENV
fi
- name: Restore Dependencies
run: dotnet restore --runtime ${{ env.RID }}
- name: Build and Publish
run: dotnet publish ./UI/MTWireGuard.csproj -c Release -o publish --runtime ${{ env.RID }} --no-restore --self-contained true /p:WarningLevel=0 /p:PublishTrimmed=true
- name: Define Tags
id: define-tags
run: |
if [ "${{ github.event_name }}" == "push" ]; then
echo "tags=techgarageir/mtwireguard:${{ github.ref_name }}, techgarageir/mtwireguard:latest, ghcr.io/${{ github.repository_owner }}/mtwireguard:${{ github.ref_name }}, ghcr.io/${{ github.repository_owner }}/mtwireguard:latest" >> $GITHUB_ENV
else
echo "tags=techgarageir/mtwireguard:${{ github.event.inputs.tag }}, ghcr.io/${{ github.repository_owner }}/mtwireguard:${{ github.event.inputs.tag }}" >> $GITHUB_ENV
fi
- name: Build and push Docker images
uses: docker/build-push-action@v6
env:
IMAGE_NAME: "techgarageir/mtwireguard"
IMAGE_NAME: "techgarageir/mtwireguard"
GHCR_IMAGE_NAME: "ghcr.io/${{ github.repository_owner }}/mtwireguard"
with:
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
context: .
file: ./Dockerfile
push: true
tags: >
${{
github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
? format('{0}:{1}, {0}:latest, {2}:{1}, {2}:latest', env.IMAGE_NAME, github.ref_name, env.GHCR_IMAGE_NAME)
: format('{0}:{1}, {2}:{1}', env.IMAGE_NAME, github.event.inputs.tag, env.GHCR_IMAGE_NAME)
}}
tags: ${{ env.tags }}
- name: Debug Output
run: |
echo "Event Name: ${{ github.event_name }}"
echo "Ref Name: ${{ github.ref_name }}"
echo "Tag Input: ${{ github.event.inputs.tag }}"
echo "Defined Tags: ${{ env.tags }}"

View file

@ -1,51 +1,10 @@
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-alpine AS publish
WORKDIR /src
# Define platform
ARG TARGETPLATFORM
ARG RID
# Set the RID based on the TARGETPLATFORM
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
echo "Setting RID for linux/amd64" ; RID=linux-x64 ; \
elif [ "$TARGETPLATFORM" = "linux/arm64" ]; then \
echo "Setting RID for linux/arm64" ; RID=linux-arm64 ; \
else \
echo "Unsupported platform $TARGETPLATFORM" ; exit 1 ; \
fi && \
echo "Using RID: $RID"
# Copy project files
COPY *.sln .
COPY UI/*.csproj ./UI/
COPY Application/*.csproj ./Application/
COPY MikrotikAPI/*.csproj ./MikrotikAPI/
COPY Serilog.Ui.SqliteProvider/*.csproj ./Serilog.Ui.SqliteProvider/
# Restore packages
RUN dotnet restore --runtime "$RID"
# Copy other files
COPY UI/. ./UI/
COPY Application/. ./Application/
COPY MikrotikAPI/. ./MikrotikAPI/
COPY Serilog.Ui.SqliteProvider/. ./Serilog.Ui.SqliteProvider/
# Publish project
RUN dotnet publish "./UI/MTWireGuard.csproj" -c Release \
-o /app/publish \
--no-restore \
--runtime "$RID" \
--self-contained true \
/p:WarningLevel=0 \
/p:PublishTrimmed=true
# Create final image and run project
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/runtime-deps:8.0-noble-chiseled-extra AS final
ENV TZ=Asia/Tehran
WORKDIR /app
EXPOSE 8080
COPY --from=publish /app/publish .
# Copy the published output from the build stage (set by the GitHub Actions workflow)
COPY publish/ .
ENTRYPOINT ["./MTWireGuard"]