Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +29 to +30

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cd WebAPI command in step 29 only affects that single step and doesn't persist to subsequent steps. Step 30's ls -al will execute in the root directory, not in the WebAPI directory. Either combine these commands with && or use working-directory parameter.

Suggested change
- run: cd WebAPI
- run: ls -al
- run: ls -al
working-directory: WebAPI

Copilot uses AI. Check for mistakes.
- 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
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cd WebAPI command in step 29 only affects that single step and doesn't persist to subsequent steps. Step 30's ls -al will execute in the root directory, not in the WebAPI directory. Either combine these commands with && or use working-directory parameter.

Suggested change
- run: dotnet restore ./WebAPI/WebAPI.csproj

Copilot uses AI. Check for mistakes.

- id: main
run: dotnet build ./WebAPI/WebAPI.csproj -c Release -o ./build

- if: ${{ steps.main.outcome == 'failure' }}
run: exit 1
38 changes: 3 additions & 35 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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/ .
Comment on lines +1 to +7

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Dockerfile now depends on a pre-existing publish/ directory but there's no documentation about how this directory should be created or what it should contain. This breaks the self-contained nature of the Dockerfile and could cause build failures if the directory doesn't exist or has incorrect contents.

Copilot uses AI. Check for mistakes.

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The simplified Dockerfile removes the security measures from the original version, including running as a non-root user. The application now runs as root, which increases security risk. Consider adding back the user creation and ownership changes.

Suggested change
# Create a non-root user and switch to it
RUN adduser --disabled-password --gecos '' appuser && \
chown -R appuser:appuser /app
USER appuser

Copilot uses AI. Check for mistakes.
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"]
ENTRYPOINT ["dotnet", "WebAPI.dll"]