Add CI/CD
This commit is contained in:
parent
8be6543a3c
commit
60f89fc780
4 changed files with 134 additions and 7 deletions
|
|
@ -8,20 +8,26 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<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.EntityFrameworkCore.Design" Version="8.0.15">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</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"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj" />
|
||||
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\SurveyBackend.Services\SurveyBackend.Services.csproj" />
|
||||
<ProjectReference Include="..\SurveyBackend.Core\SurveyBackend.Core.csproj"/>
|
||||
<ProjectReference Include="..\SurveyBackend.Infrastructure\SurveyBackend.Infrastructure.csproj"/>
|
||||
<ProjectReference Include="..\SurveyBackend.Services\SurveyBackend.Services.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</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"
|
||||
Loading…
Add table
Add a link
Reference in a new issue