feat: pipeline
This commit is contained in:
parent
f63fc627e3
commit
b5da7d1b2e
1 changed files with 32 additions and 20 deletions
|
|
@ -1,35 +1,27 @@
|
|||
pipeline:
|
||||
# Build and test stage
|
||||
# Build and test backend
|
||||
build-and-test:
|
||||
image: mcr.microsoft.com/dotnet/sdk:9.0
|
||||
commands:
|
||||
# Restore dependencies
|
||||
- dotnet restore GermanApp/GermanApp.csproj
|
||||
|
||||
# Build the backend
|
||||
- dotnet build GermanApp/GermanApp.csproj --no-restore --configuration Release
|
||||
|
||||
# Run unit tests
|
||||
- dotnet test Tests/GermanApp.Tests.Unit.csproj --no-build --configuration Release --verbosity normal
|
||||
|
||||
# Run integration tests
|
||||
- dotnet test Tests/GermanApp.Tests.Integration.csproj --no-build --configuration Release --verbosity normal
|
||||
- dotnet test Tests/GermanApp.Tests.Unit.csproj --no-build --configuration Release
|
||||
- dotnet test Tests/GermanApp.Tests.Integration.csproj --no-build --configuration Release
|
||||
when:
|
||||
# Run on all branches
|
||||
branch:
|
||||
- main
|
||||
- feature/*
|
||||
- bugfix/*
|
||||
- refactor/*
|
||||
|
||||
# Docker build and push stage
|
||||
docker-build:
|
||||
# Build and push backend image
|
||||
build-backend:
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: GermanApp/Dockerfile
|
||||
context: GermanApp
|
||||
registry: registry.lrhdev.dk
|
||||
repo: registry.lrhdev.dk/lasserh/deutschlernen
|
||||
repo: registry.lrhdev.dk/lasserh/deutschlernen-backend
|
||||
tags:
|
||||
- latest
|
||||
- ${CI_COMMIT_SHA:0:8}
|
||||
|
|
@ -38,28 +30,48 @@ pipeline:
|
|||
password:
|
||||
from_secret: docker_password
|
||||
when:
|
||||
# Only build and push on main branch
|
||||
branch:
|
||||
- main
|
||||
# Only run if build-and-test succeeded
|
||||
status:
|
||||
- success
|
||||
|
||||
# Deploy stage
|
||||
# Build and push frontend image
|
||||
build-frontend:
|
||||
image: plugins/docker
|
||||
settings:
|
||||
dockerfile: german-app-frontend/Dockerfile
|
||||
context: german-app-frontend
|
||||
registry: registry.lrhdev.dk
|
||||
repo: registry.lrhdev.dk/lasserh/deutschlernen-frontend
|
||||
tags:
|
||||
- latest
|
||||
- ${CI_COMMIT_SHA:0:8}
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
when:
|
||||
branch:
|
||||
- main
|
||||
status:
|
||||
- success
|
||||
|
||||
# Deploy to production
|
||||
deploy:
|
||||
image: alpine
|
||||
commands:
|
||||
- echo "Deploying to deutsch.lrhdev.dk..."
|
||||
- apk add --no-cache openssh-client
|
||||
- mkdir -p ~/.ssh
|
||||
- echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
|
||||
- chmod 600 ~/.ssh/id_rsa
|
||||
- ssh-keyscan deutsch.lrhdev.dk >> ~/.ssh/known_hosts
|
||||
- ssh root@deutsch.lrhdev.dk "cd /path/to/app && docker-compose pull backend && docker-compose up -d backend"
|
||||
# Pull new images and restart containers
|
||||
- ssh ci-deploy@deutsch.lrhdev.dk "cd /opt/deutschlernen && docker-compose pull && docker-compose up -d"
|
||||
# Reload nginx to pick up any new configurations
|
||||
- ssh ci-deploy@deutsch.lrhdev.dk "nginx -t && nginx -s reload"
|
||||
secrets:
|
||||
- SSH_PRIVATE_KEY
|
||||
when:
|
||||
# Only deploy on main branch after successful docker-build
|
||||
branch:
|
||||
- main
|
||||
status:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue