Skip to content

Commit 161aee6

Browse files
Merge pull request #12 from nullinside-development-group/feat/deploy
feat: setting up deployment of application
2 parents 2a8710b + 0f5c732 commit 161aee6

File tree

10 files changed

+100
-39
lines changed

10 files changed

+100
-39
lines changed

.github/workflows/codeql.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ jobs:
2929
steps:
3030
- name: Checkout repository
3131
uses: actions/checkout@v4
32+
with:
33+
submodules: 'recursive'
3234

3335
# Install the .NET Core workload
3436
- name: Install .NET Core
3537
uses: actions/setup-dotnet@v3
3638
with:
37-
dotnet-version: 8.x.x
39+
dotnet-version: 9.x.x
3840

3941
# Execute the build
4042
- name: Execute Release Build
@@ -49,12 +51,14 @@ jobs:
4951
steps:
5052
- name: Checkout repository
5153
uses: actions/checkout@v4
54+
with:
55+
submodules: 'recursive'
5256

5357
# Install the .NET Core workload
5458
- name: Install .NET Core
5559
uses: actions/setup-dotnet@v3
5660
with:
57-
dotnet-version: 8.x.x
61+
dotnet-version: 9.x.x
5862

5963
# Execute the tests
6064
- name: Execute Tests
@@ -92,6 +96,8 @@ jobs:
9296
steps:
9397
- name: Checkout repository
9498
uses: actions/checkout@v4
99+
with:
100+
submodules: 'recursive'
95101

96102
# Initializes the CodeQL tools for scanning.
97103
- name: Initialize CodeQL
@@ -114,7 +120,7 @@ jobs:
114120
- name: Install .NET Core
115121
uses: actions/setup-dotnet@v3
116122
with:
117-
dotnet-version: 8.x.x
123+
dotnet-version: 9.x.x
118124

119125
# Execute the build
120126
- name: Execute Build

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
FROM mcr.microsoft.com/dotnet/runtime:8.0 AS base
1+
FROM mcr.microsoft.com/dotnet/runtime:9.0 AS base
22
USER $APP_UID
33
WORKDIR /app
4+
EXPOSE 8080
5+
EXPOSE 8081
46

5-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
7+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
68
ARG BUILD_CONFIGURATION=Release
79
WORKDIR /src
8-
RUN ls -a
10+
911
COPY ["src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj", "Nullinside.Cicd.GitHub/"]
1012
RUN dotnet restore "Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj"
1113
COPY . .

docker-compose.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: nullinside-cicd-github
2+
services:
3+
nullinside-cicd-github:
4+
build:
5+
context: .
6+
tags:
7+
- "nullinside-cicd-github:latest"
8+
logging:
9+
driver: loki
10+
options:
11+
loki-url: 'http://192.168.1.4:3100/loki/api/v1/push'
12+
container_name: nullinside-cicd-github
13+
environment:
14+
- GITHUB_PAT
15+
ports:
16+
- 8081:8080
17+
- 8082:8081
18+
restart: unless-stopped
19+
image: nullinside-cicd-github:latest

go.sh

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
docker build -t nullinside-cicd-github:latest .
2-
docker container stop nullinside-cicd-github
3-
docker container prune -f
4-
docker run -d --name=nullinside-cicd-github -e GITHUB_PAT=$GITHUB_PAT --restart unless-stopped nullinside-cicd-github:latest
1+
docker compose build
2+
docker compose down
3+
docker compose up -d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
namespace Nullinside.Cicd.GitHub;
22

3+
/// <summary>
4+
/// Constants used throughout the appliction.
5+
/// </summary>
36
public static class Constants {
7+
/// <summary>
8+
/// The github project name
9+
/// </summary>
410
public const string GITHUB_ORG = "nullinside-development-group";
11+
12+
/// <summary>
13+
/// The github project's unique identifier on github.
14+
/// </summary>
515
public const int GITHUB_PROJECT_NUM = 1;
616
}

src/Nullinside.Cicd.GitHub/Nullinside.Cicd.GitHub.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net8.0</TargetFramework>
5+
<TargetFramework>net9.0</TargetFramework>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
9+
<LangVersion>default</LangVersion>
910
</PropertyGroup>
1011

1112
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@@ -18,12 +19,12 @@
1819
</PropertyGroup>
1920

2021
<ItemGroup>
21-
<PackageReference Include="log4net" Version="3.0.4" />
22-
<PackageReference Include="Octokit" Version="14.0.0" />
22+
<PackageReference Include="log4net" Version="3.0.4"/>
23+
<PackageReference Include="Octokit" Version="14.0.0"/>
2324
</ItemGroup>
2425

2526
<ItemGroup>
26-
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj" />
27+
<ProjectReference Include="..\octokit.graphql.net\src\Octokit.GraphQL\Octokit.GraphQL.csproj"/>
2728
</ItemGroup>
2829

2930
</Project>

src/Nullinside.Cicd.GitHub/Program.cs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,30 @@
1818
.Where(o => null != o)
1919
.ToArray();
2020

21-
var client = new GitHubClient(new ProductHeaderValue("nullinside")) {
22-
Credentials = new Credentials(Environment.GetEnvironmentVariable("GITHUB_PAT"))
23-
};
24-
25-
var graphQl = new Connection(new Octokit.GraphQL.ProductHeaderValue("nullinside"),
26-
Environment.GetEnvironmentVariable("GITHUB_PAT"));
27-
28-
ID projectId = await graphQl.Run(new Query()
29-
.Organization(Constants.GITHUB_ORG)
30-
.ProjectV2(Constants.GITHUB_PROJECT_NUM)
31-
.Select(p => p.Id));
32-
33-
IReadOnlyList<Repository>? repository = await client.Repository.GetAllForOrg(Constants.GITHUB_ORG);
34-
foreach (Repository repo in repository) {
35-
if (repo.Private) {
36-
continue;
37-
}
38-
39-
foreach (IRepoRule? rule in rules) {
40-
await rule.Handle(client, graphQl, projectId, repo);
21+
while (true) {
22+
var client = new GitHubClient(new ProductHeaderValue("nullinside")) {
23+
Credentials = new Credentials(Environment.GetEnvironmentVariable("GITHUB_PAT"))
24+
};
25+
26+
var graphQl = new Connection(new Octokit.GraphQL.ProductHeaderValue("nullinside"),
27+
Environment.GetEnvironmentVariable("GITHUB_PAT"));
28+
29+
ID projectId = await graphQl.Run(new Query()
30+
.Organization(Constants.GITHUB_ORG)
31+
.ProjectV2(Constants.GITHUB_PROJECT_NUM)
32+
.Select(p => p.Id));
33+
34+
IReadOnlyList<Repository>? repository = await client.Repository.GetAllForOrg(Constants.GITHUB_ORG);
35+
foreach (Repository repo in repository) {
36+
if (repo.Private) {
37+
continue;
38+
}
39+
40+
foreach (IRepoRule? rule in rules) {
41+
await rule!.Handle(client, graphQl, projectId, repo);
42+
}
4143
}
44+
45+
Console.WriteLine("Waiting for next execution time...");
46+
Task.WaitAll(Task.Delay(TimeSpan.FromMinutes(5)));
4247
}

src/Nullinside.Cicd.GitHub/Rule/AssociateIssuesWithProject.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
namespace Nullinside.Cicd.GitHub.Rule;
1010

11+
/// <summary>
12+
/// Handles associating issues with the project automatically.
13+
/// </summary>
1114
public class AssociateIssuesWithProject : IRepoRule {
15+
/// <inheritdoc />
1216
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
1317
if (!repo.HasIssues) {
1418
return;

src/Nullinside.Cicd.GitHub/Rule/CreateRulesets.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88

99
namespace Nullinside.Cicd.GitHub.Rule;
1010

11+
/// <summary>
12+
/// Creates the branch merging rules based on the code bases' language.
13+
/// </summary>
1114
public class CreateRulesets : IRepoRule {
15+
/// <inheritdoc />
1216
public async Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo) {
1317
// This currently doesn't run properly. You get an error about not specifying multiple Parameters on the status
1418
// checks. Waiting on an update from the source library to not include nulls in the compiled query.
@@ -18,19 +22,19 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
1822
.Rulesets()
1923
.AllPages()
2024
.Select(i => i.Name));
21-
25+
2226
string? expectedRuleset =
2327
rulesets.FirstOrDefault(r => "main".Equals(r, StringComparison.InvariantCultureIgnoreCase));
2428
if (null != expectedRuleset) {
2529
return;
2630
}
27-
31+
2832
ID id = await graphQl.Run(new Query()
2933
.Repository(repo.Name, Constants.GITHUB_ORG)
3034
.Select(i => i.Id));
31-
35+
3236
Console.WriteLine($"{repo.Name}: Creating default ruleset");
33-
StatusCheckConfigurationInput[] statusChecks = null;
37+
StatusCheckConfigurationInput[]? statusChecks = null;
3438
if ("Typescript".Equals(repo.Language, StringComparison.InvariantCultureIgnoreCase)) {
3539
statusChecks = new[] {
3640
new StatusCheckConfigurationInput {
@@ -90,7 +94,7 @@ public async Task Handle(GitHubClient client, Connection graphQl, ID projectId,
9094
}
9195
});
9296
}
93-
97+
9498
await graphQl.Run(new Mutation()
9599
.CreateRepositoryRuleset(new Arg<CreateRepositoryRulesetInput>(new CreateRepositoryRulesetInput {
96100
SourceId = id,

src/Nullinside.Cicd.GitHub/Rule/IRepoRule.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@
55

66
namespace Nullinside.Cicd.GitHub.Rule;
77

8+
/// <summary>
9+
/// Contracts for executing code against a project.
10+
/// </summary>
811
public interface IRepoRule {
12+
/// <summary>
13+
/// Handles performing the rule updates.
14+
/// </summary>
15+
/// <param name="client">The github rest api client.</param>
16+
/// <param name="graphQl">The github graphql client.</param>
17+
/// <param name="projectId">The unique identifier of the project.</param>
18+
/// <param name="repo">The git repo being updated.</param>
19+
/// <returns></returns>
920
Task Handle(GitHubClient client, Connection graphQl, ID projectId, Repository repo);
1021
}

0 commit comments

Comments
 (0)