Add CI/CD
This commit is contained in:
parent
8be6543a3c
commit
60f89fc780
4 changed files with 134 additions and 7 deletions
25
.gitlab-ci.yml
Normal file
25
.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
stages:
|
||||||
|
- .pre
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
variables:
|
||||||
|
GIT_SUBMODULE_STRATEGY: recursive
|
||||||
|
PUBLISH_DIR: BackendPublish
|
||||||
|
|
||||||
|
top-level-job:
|
||||||
|
stage: .pre
|
||||||
|
image: alpine:latest
|
||||||
|
script:
|
||||||
|
- echo "Starting pipeline"
|
||||||
|
|
||||||
|
include:
|
||||||
|
- local: '/SurveyBackend/backend.gitlab-ci.yml'
|
||||||
|
rules:
|
||||||
|
- changes:
|
||||||
|
- 'SurveyBackend/*'
|
||||||
|
- local: '/SurveyFrontend/frontend.gitlab-ci.yml'
|
||||||
|
rules:
|
||||||
|
- changes:
|
||||||
|
- 'SurveyFrontend/*'
|
||||||
|
|
@ -8,20 +8,26 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.14" />
|
<Content Update="appsettings.*.json">
|
||||||
|
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.14"/>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
|
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2"/>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.15">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.15">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.15" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.15"/>
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj" />
|
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj"/>
|
||||||
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj" />
|
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj"/>
|
||||||
<ProjectReference Include="..\SurveyBackend.Services\SurveyBackend.Services.csproj" />
|
<ProjectReference Include="..\SurveyBackend.Services\SurveyBackend.Services.csproj"/>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
59
SurveyBackend/backend.gitlab-ci.yml
Normal file
59
SurveyBackend/backend.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
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"
|
||||||
|
- scp -r $PUBLISH_DIR/. $DEPLOY_USER@$DEPLOY_HOST:$BACKEND_DEPLOY_PATH
|
||||||
|
- >
|
||||||
|
ssh $DEPLOY_USER@$DEPLOY_HOST "
|
||||||
|
cd $BACKEND_DEPLOY_PATH &&
|
||||||
|
echo 'Running migrations' &&
|
||||||
|
./efbundle &&
|
||||||
|
echo 'Restarting systemd service' &&
|
||||||
|
systemctl --user restart SurveyBackend.service"
|
||||||
37
SurveyFrontend/frontend.gitlab-ci.yml
Normal file
37
SurveyFrontend/frontend.gitlab-ci.yml
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
stages:
|
||||||
|
- build
|
||||||
|
- test
|
||||||
|
- deploy
|
||||||
|
|
||||||
|
frontend-build-job:
|
||||||
|
image: node:20-alpine
|
||||||
|
stage: build
|
||||||
|
script:
|
||||||
|
- cd SurveyFrontend
|
||||||
|
- npm install
|
||||||
|
- npm run build
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- SurveyFrontend/dist
|
||||||
|
expire_in: 1 hour
|
||||||
|
|
||||||
|
frontend-test-job:
|
||||||
|
image: alpine:latest
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- echo "Here we would run some tests if I knew how to use them"
|
||||||
|
|
||||||
|
frontend-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 frontend to $DEPLOY_HOST"
|
||||||
|
- scp -r SurveyFrontend/dist/* $DEPLOY_USER@$DEPLOY_HOST:$FRONTEND_DEPLOY_PATH
|
||||||
Loading…
Add table
Add a link
Reference in a new issue