diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 03727e9e..a8179d97 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -25,7 +25,17 @@ jobs: cache-dependency-path: frontend/package-lock.json - name: Restore .NET dependencies - run: dotnet restore src/UsingCash.sln + shell: bash + run: | + set -euo pipefail + if [ -n "${NUGET_CACHE_URL:-}" ]; then + echo "Using NuGet cache: ${NUGET_CACHE_URL}" + dotnet restore src/UsingCash.sln \ + --source "${NUGET_CACHE_URL}" \ + --source "https://api.nuget.org/v3/index.json" + else + dotnet restore src/UsingCash.sln + fi - name: Build .NET run: dotnet build src/UsingCash.sln --no-restore -c Release @@ -34,7 +44,14 @@ jobs: run: dotnet test src/UsingCash.sln --no-build -c Release --verbosity normal - name: Install frontend dependencies - run: npm ci + shell: bash + run: | + set -euo pipefail + if [ -n "${NPM_REGISTRY_URL:-}" ]; then + echo "Using npm registry: ${NPM_REGISTRY_URL}" + npm config set registry "${NPM_REGISTRY_URL}" + fi + npm ci working-directory: frontend - name: Lint frontend @@ -53,6 +70,16 @@ jobs: - uses: actions/checkout@v4 - name: Build Docker image - run: docker build -t using-cash:${{ github.sha }} -t using-cash:latest . + shell: bash + run: | + set -euo pipefail + build_args=() + if [ -n "${NUGET_CACHE_URL:-}" ]; then + build_args+=(--build-arg "NUGET_CACHE_URL=${NUGET_CACHE_URL}") + fi + if [ -n "${NPM_REGISTRY_URL:-}" ]; then + build_args+=(--build-arg "NPM_REGISTRY_URL=${NPM_REGISTRY_URL}") + fi + docker build "${build_args[@]}" -t using-cash:${{ github.sha }} -t using-cash:latest . # Push to registry can be added when a registry is configured diff --git a/Dockerfile b/Dockerfile index b413f776..9f607646 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ FROM node:20-slim AS frontend-build WORKDIR /app/frontend COPY frontend/package.json frontend/package-lock.json ./ -RUN npm ci +ARG NPM_REGISTRY_URL +RUN if [ -n "$NPM_REGISTRY_URL" ]; then npm config set registry "$NPM_REGISTRY_URL"; fi \ + && npm ci COPY frontend/ ./ RUN npm run build @@ -16,7 +18,12 @@ COPY src/UsingCash.Api/*.csproj src/UsingCash.Api/ COPY src/UsingCash.Backend/*.csproj src/UsingCash.Backend/ COPY src/UsingCash.Migration/*.csproj src/UsingCash.Migration/ COPY src/UsingCash.Tests/*.csproj src/UsingCash.Tests/ -RUN dotnet restore src/UsingCash.sln +ARG NUGET_CACHE_URL +RUN if [ -n "$NUGET_CACHE_URL" ]; then \ + dotnet restore src/UsingCash.sln --source "$NUGET_CACHE_URL" --source "https://api.nuget.org/v3/index.json"; \ + else \ + dotnet restore src/UsingCash.sln; \ + fi COPY src/ src/ COPY --from=frontend-build /app/src/UsingCash.Api/wwwroot src/UsingCash.Api/wwwroot/ RUN dotnet publish src/UsingCash.Api/UsingCash.Api.csproj -c Release -o /app/publish --no-restore