diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 0000000..2e0ca12 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,66 @@ +name: CD + +on: + push: + branches: [main, testci] + +permissions: + id-token: write + contents: write + actions: write + deployments: write + pages: write + pull-requests: write + packages: write + +jobs: + deployment: + env: + HUSKY: 0 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-dotnet@v5 + with: + dotnet-version: "9.0.x" + + - run: cd WebAPI + - run: ls -al + - run: dotnet restore ./WebAPI/WebAPI.csproj + + - id: main + run: dotnet build ./WebAPI/WebAPI.csproj -c Release -o ./build + + - if: ${{ steps.main.outcome == 'failure' }} + run: exit 1 + + - id: publish + run: dotnet publish ./WebAPI/WebAPI.csproj -c Release -o ./publish /p:UseAppHost=false + + # Make a lowercase owner for GHCR image path (Docker requires lowercase repo names) + - name: Compute lowercased owner + id: vars + run: echo "OWNER_LC=${GITHUB_REPOSITORY_OWNER,,}" >> $GITHUB_ENV + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to GHCR + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push Docker image + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: | + ghcr.io/${{ env.OWNER_LC }}/ev-rental-be:latest + ghcr.io/${{ env.OWNER_LC }}/ev-rental-be:${{ github.sha }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b709354 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: CI + +on: + pull_request: + types: [synchronize, opened, reopened, edited] + +permissions: + id-token: write + contents: write + actions: write + deployments: write + pages: write + pull-requests: write + packages: write + +jobs: + main-ci: + env: + HUSKY: 0 + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - uses: actions/setup-dotnet@v5 + with: + dotnet-version: "9.0.x" + + - run: cd WebAPI + - run: ls -al + - run: dotnet restore ./WebAPI/WebAPI.csproj + + - id: main + run: dotnet build ./WebAPI/WebAPI.csproj -c Release -o ./build + + - if: ${{ steps.main.outcome == 'failure' }} + run: exit 1 diff --git a/Dockerfile b/Dockerfile index 69432c1..3db7bca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,41 +1,9 @@ -# syntax=docker/dockerfile:1 -############################################ -# Base runtime image -############################################ -FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:9.0 WORKDIR /app EXPOSE 8080 ENV ASPNETCORE_URLS=http://+:8080 \ DOTNET_EnableDiagnostics=0 -# Add DefaultConnection (empty by default; override at runtime) -# ENV -# ConnectionStrings__DefaultConnection="" -# Jwt__Key="" -# Jwt__AccessTokenExpiration="10" -# Jwt__RefreshTokenExpiration="7" -# Jwt__REFRESH_TOKEN_CLAIM_TYPE="RefreshToken" -# Jwt__REFRESH_TOKEN_EXPIRATION_CLAIM_TYPE="RefreshTokenExpiration" -############################################ -# Build & publish -############################################ -FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build -WORKDIR /src -COPY ["WebAPI/WebAPI.csproj", "./"] -RUN dotnet restore "WebAPI.csproj" -COPY . . -RUN dotnet build "WebAPI.csproj" -c Release -o /app/build +COPY publish/ . -FROM build AS publish -RUN dotnet publish "WebAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false - -############################################ -# Final image -############################################ -FROM base AS final -RUN addgroup --system app && adduser --system --ingroup app appuser -WORKDIR /app -COPY --from=publish /app/publish . -RUN chown -R appuser:app /app -USER appuser -ENTRYPOINT ["dotnet", "WebAPI.dll"] \ No newline at end of file +ENTRYPOINT ["dotnet", "WebAPI.dll"]