diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..f0b11f8 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,121 @@ +stages: + - restore + - build + - test + - docker_build + - deploy + +variables: + # Use Docker-in-Docker for building images + DOCKER_DRIVER: overlay2 + DOCKER_TLS_CERTDIR: "" + +# Cache for NuGet packages +cache: + key: ${CI_COMMIT_REF_SLUG} + paths: + - .nuget/packages/ + - frontend/node_modules/ + +# ------------------------------------------------------------------- +# Backend (ASP.NET Core) jobs +# ------------------------------------------------------------------- +restore_backend: + stage: restore + image: mcr.microsoft.com/dotnet/sdk:10.0 + script: + - dotnet restore backend/GiecChallenge/GiecChallenge.csproj + artifacts: + paths: + - backend/GiecChallenge/obj/ + - backend/GiecChallenge/bin/ + expire_in: 1 hour + +build_backend: + stage: build + image: mcr.microsoft.com/dotnet/sdk:10.0 + needs: [restore_backend] + script: + - dotnet build backend/GiecChallenge/GiecChallenge.csproj -c Release -o out + artifacts: + paths: + - out/ + expire_in: 1 hour + +test_backend: + stage: test + image: mcr.microsoft.com/dotnet/sdk:10.0 + needs: [build_backend] + script: + - dotnet test backend/GiecChallenge.test/GiecChallenge.test.csproj --no-build --verbosity normal + artifacts: + when: always + reports: + junit: test-results.xml + expire_in: 1 hour + +# ------------------------------------------------------------------- +# Frontend (React) jobs +# ------------------------------------------------------------------- +install_frontend: + stage: restore + image: node:14-alpine + script: + - cd frontend + - npm ci + cache: + key: ${CI_COMMIT_REF_SLUG}-frontend + paths: + - frontend/node_modules/ + artifacts: + paths: + - frontend/node_modules/ + expire_in: 1 hour + +build_frontend: + stage: build + image: node:14-alpine + needs: [install_frontend] + script: + - cd frontend + - npm run build + artifacts: + paths: + - frontend/build/ + expire_in: 1 hour + +# ------------------------------------------------------------------- +# Docker images +# ------------------------------------------------------------------- +docker_build_backend: + stage: docker_build + image: docker:latest + services: + - docker:dind + needs: [test_backend] + script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build -t $CI_REGISTRY_IMAGE/backend:${CI_COMMIT_SHA:0:8} -f backend/GiecChallenge/Dockerfile . + - docker push $CI_REGISTRY_IMAGE/backend:${CI_COMMIT_SHA:0:8} + +docker_build_frontend: + stage: docker_build + image: docker:latest + services: + - docker:dind + needs: [build_frontend] + script: + - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY + - docker build -t $CI_REGISTRY_IMAGE/frontend:${CI_COMMIT_SHA:0:8} -f frontend/Dockerfile . + - docker push $CI_REGISTRY_IMAGE/frontend:${CI_COMMIT_SHA:0:8} + +# ------------------------------------------------------------------- +# Deploy (optional – placeholder) +# ------------------------------------------------------------------- +deploy: + stage: deploy + image: alpine:latest + script: + - echo "Deploy step placeholder – add your deployment commands here." + only: + - main \ No newline at end of file diff --git a/backend/GiecChallenge/Dockerfile b/backend/GiecChallenge/Dockerfile index c3b2f9f..aa644d7 100644 --- a/backend/GiecChallenge/Dockerfile +++ b/backend/GiecChallenge/Dockerfile @@ -1,10 +1,10 @@ -FROM mcr.microsoft.com/dotnet/aspnet:7.0 AS base +FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS base ENV ASPNETCORE_ENVIRONMENT Docker WORKDIR /app EXPOSE 80 EXPOSE 443 -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build ENV ASPNETCORE_ENVIRONMENT Docker WORKDIR /src-backend COPY ./backend/GiecChallenge/GiecChallenge.csproj .