Skip to content

Commit

Permalink
Merge pull request #1 from RieBi/ci-cd
Browse files Browse the repository at this point in the history
Provide CI/CD functionality
  • Loading branch information
RieBi authored Jul 22, 2024
2 parents be47121 + c11d250 commit 0832afa
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 19 deletions.
30 changes: 30 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
48 changes: 48 additions & 0 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: DeployCountrie

on:
push:
branches: [ "master" ]

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest

env:
ConnectionStrings__PostgreConnectionRelease: ${{ secrets.DATABASE_CONNECTION }}

steps:
- name: Check out code
uses: actions/checkout@v4

- name: 'Copy Dockerfile to root'
run: cp Web/Dockerfile ./Dockerfile

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore

- id: 'auth'
uses: 'google-github-actions/auth@v2'
with:
credentials_json: '${{ secrets.GCP_CREDENTIALS }}'

- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v2'

- name: 'Use gcloud CLI'
run: 'gcloud info'

- name: 'Build the docker image'
run: 'gcloud builds submit --tag europe-central2-docker.pkg.dev/countrie/repo/countrie:latest .'

- name: 'Deploy to Cloud Run'
run: 'gcloud run deploy countrie --image europe-central2-docker.pkg.dev/countrie/repo/countrie:latest --region europe-central2 --allow-unauthenticated --project countrie --max-instances=4 --update-env-vars=ConnectionStrings__PostgreConnectionRelease="${{ secrets.DATABASE_CONNECTION }}"'
28 changes: 28 additions & 0 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
2 changes: 1 addition & 1 deletion CountRie.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Application", "Application\
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data", "Data\Data.csproj", "{478FD976-665C-4EE3-A99D-B43D79DB3360}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Web", "Web\Web.csproj", "{F30B9D7C-A1F6-40A5-81B3-C34C454055C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Web", "Web\Web.csproj", "{F30B9D7C-A1F6-40A5-81B3-C34C454055C2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
29 changes: 29 additions & 0 deletions Web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 8080
EXPOSE 8081

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Web/Web.csproj", "Web/"]
COPY ["Application/Application.csproj", "Application/"]
COPY ["Data/Data.csproj", "Data/"]
RUN dotnet restore "./Web/Web.csproj"
COPY . .
WORKDIR "/src/Web"
RUN dotnet build "./Web.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Web.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENV TEST_ENV=TEST_ENV_VALUE
RUN export DOTNET_ENVIRONMENT=Release
ENTRYPOINT ["dotnet", "Web.dll"]
11 changes: 10 additions & 1 deletion Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Application.Authorization;
using Microsoft.AspNetCore.Mvc.Razor;
using Application.Services.UserManagement;
using System.Data.Common;

var builder = WebApplication.CreateBuilder(args);

Expand Down Expand Up @@ -60,7 +61,15 @@
});

builder.Services.AddDbContext<DataContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("PostgreConnection")));
{
string? connectionString;
if (builder.Environment.IsDevelopment())
connectionString = builder.Configuration.GetConnectionString("PostgreConnection");
else
connectionString = builder.Configuration.GetConnectionString("PostgreConnectionRelease");

options.UseNpgsql(connectionString);
});

builder.Services.AddAutoMapper(
typeof(Application.MappingProfiles),
Expand Down
46 changes: 29 additions & 17 deletions Web/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8402",
"sslPort": 44370
}
},
{
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5258",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "http://localhost:5258"
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7245;http://localhost:5258",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"dotnetRunMessages": true,
"applicationUrl": "https://localhost:7245;http://localhost:5258"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Container (Dockerfile)": {
"commandName": "Docker",
"launchBrowser": true,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_HTTPS_PORTS": "8081",
"ASPNETCORE_HTTP_PORTS": "8080",
"ASPNETCORE_ENVIRONMENT": "Production"
},
"publishAllPorts": true,
"useSSL": true
}
},
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8402",
"sslPort": 44370
}
}
}
}
2 changes: 2 additions & 0 deletions Web/Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>6dda408d-76f8-48f6-93ff-5253f1de0e3e</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
Expand All @@ -22,6 +23,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.3" />
</ItemGroup>

Expand Down

0 comments on commit 0832afa

Please sign in to comment.