diff --git a/.github/workflows/Release.yml b/.github/workflows/Release.yml index 65c5938..31f5ceb 100644 --- a/.github/workflows/Release.yml +++ b/.github/workflows/Release.yml @@ -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 }}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 82e06aa..ca30830 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"]