survey-webapp/SurveyBackend/backend.gitlab-ci.yml
2025-04-23 22:36:52 +05:00

63 lines
No EOL
1.9 KiB
YAML

stages:
- build
- test
- deploy
backend-build-job:
image: mcr.microsoft.com/dotnet/sdk:8.0
stage: build
script:
- dotnet restore SurveyBackend/SurveyBackend.sln
- dotnet tool install --global dotnet-ef
- export PATH="$PATH:/root/.dotnet/tools"
- >
dotnet ef migrations bundle
--self-contained
-r linux-x64
-p SurveyBackend/SurveyBackend.Infrastructure/SurveyBackend.Infrastructure.csproj
-s ./SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj
-o $PUBLISH_DIR/efbundle
- >
dotnet publish SurveyBackend/SurveyBackend.API/SurveyBackend.API.csproj
-c Release -r linux-x64 --self-contained true
/p:PublishReadyToRun=true
/p:PublishSingleFile=true
/p:IncludeNativeLibrariesForSelfExtract=false
/p:TrimUnusedDependencies=false
-o $PUBLISH_DIR
artifacts:
paths:
- $PUBLISH_DIR
expire_in: 1 hour
backend-test-job:
image: alpine:latest
stage: test
script:
- echo "Here we would run some tests if I knew how to use them"
backend-deploy-job:
image: alpine:latest
stage: deploy
rules:
- if: '$CI_COMMIT_BRANCH == "main"'
before_script:
- apk add --no-cache openssh
- mkdir -p ~/.ssh
- echo "$DEPLOY_KEY" | base64 -d > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh-keyscan -H "$DEPLOY_HOST" >> ~/.ssh/known_hosts
script:
- echo "Deploying backend to $DEPLOY_HOST"
- echo "Stopping service"
- ssh $DEPLOY_USER@$DEPLOY_HOST "systemctl --user stop SurveyBackend.service"
- echo "Copying new build"
- scp -r $PUBLISH_DIR/. $DEPLOY_USER@$DEPLOY_HOST:$BACKEND_DEPLOY_PATH
- echo "okeey let's go"
- >
ssh $DEPLOY_USER@$DEPLOY_HOST "
cd $BACKEND_DEPLOY_PATH &&
echo 'Running migrations' &&
./efbundle &&
echo 'Restarting systemd service' &&
systemctl --user restart SurveyBackend.service"