Skip to content

Commit 0a4684f

Browse files
committed
rework CICD
1 parent 7f2d239 commit 0a4684f

File tree

6 files changed

+90
-124
lines changed

6 files changed

+90
-124
lines changed

.github/actions/kubernetes-rollout-restart/action.yml

Lines changed: 0 additions & 58 deletions
This file was deleted.

.github/workflows/ci-build.yml

Lines changed: 79 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
on:
22
push:
33
branches:
4-
- master
5-
- develop
4+
- '**'
65
pull_request:
76
branches:
8-
- master
9-
- develop
7+
- '**'
108
types: [ opened, reopened, synchronize ]
119
workflow_call:
1210
workflow_dispatch:
@@ -15,11 +13,42 @@ name: ci-build
1513

1614
env:
1715
REGISTRY: ghcr.io
16+
DOTNET_VERSION: 10.0.x
1817

1918
jobs:
2019

20+
tests:
21+
name: Tests (${{ matrix.name }})
22+
runs-on: ubuntu-latest
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
include:
27+
- name: common-unit
28+
project: DesktopRepositoryServer.Tests/DesktopRepositoryServer.Tests.csproj
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v5
33+
34+
- uses: actions/setup-dotnet@v5
35+
with:
36+
dotnet-version: '${{ env.DOTNET_VERSION }}'
37+
38+
- name: Run ${{ matrix.name }} tests
39+
run: |
40+
set -euo pipefail
41+
dotnet test -c Release ${{ matrix.project }}
42+
2143
build:
44+
name: Build (${{ matrix.image }})
2245
runs-on: ubuntu-latest
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
include:
50+
- dockerfile: docker/API.Dockerfile
51+
image: desktop-repository-server
2352

2453
steps:
2554
- name: Checkout
@@ -35,44 +64,57 @@ jobs:
3564
username: ${{ github.actor }}
3665
password: ${{ secrets.GITHUB_TOKEN }}
3766

38-
- name: Extract metadata (tags, labels) for Docker
39-
id: meta
40-
uses: docker/metadata-action@v5
67+
- name: Build ${{ matrix.image }}
68+
uses: ./.github/actions/build-app
69+
with:
70+
dockerfile: ${{ matrix.dockerfile }}
71+
push: ${{ inputs.push || (github.ref_protected && github.event_name != 'pull_request') }}
72+
image: ${{ matrix.image }}
73+
platforms: ${{ inputs.platforms || 'linux/amd64' }}
74+
tag-prefix: ${{ inputs.tag-prefix || 'rn' }}
75+
76+
promote-image:
77+
name: Promote Image (${{ matrix.image }})
78+
needs: [build, tests]
79+
runs-on: ubuntu-latest
80+
if: ${{ inputs.push || (github.ref_protected && github.event_name != 'pull_request') }}
81+
strategy:
82+
fail-fast: false
83+
matrix:
84+
include:
85+
- image: desktop-repository-server
86+
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v5
90+
91+
- name: Log in to Container Registry
92+
uses: docker/login-action@v3
4193
with:
42-
images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/desktop-repository-server
43-
flavor: |
44-
latest=false
45-
tags: |
46-
type=raw,value={{branch}},enable=${{ github.ref_type == 'branch' && github.event_name != 'pull_request' }}
47-
type=ref,event=branch
48-
type=ref,event=pr
94+
registry: ${{ env.REGISTRY }}
95+
username: ${{ github.actor }}
96+
password: ${{ secrets.GITHUB_TOKEN }}
4997

50-
- name: Build and push
51-
uses: docker/build-push-action@v6
98+
- name: Promote Manifest ${{ matrix.image }}
99+
uses: ./.github/actions/promote-image
52100
with:
53-
context: .
54-
file: Dockerfile
55-
push: ${{ github.event_name != 'pull_request' }}
56-
tags: ${{ steps.meta.outputs.tags }}
57-
labels: ${{ steps.meta.outputs.labels }}
58-
platforms: linux/amd64,linux/arm64
101+
image: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.image }}
102+
run-tag: ${{ inputs.tag-prefix || 'rn' }}-${{ github.run_number }}-a${{ github.run_attempt }}
103+
latest: ${{ inputs.latest || false }}
59104

60-
deploy-production:
105+
deploy-prod-workflow:
61106
runs-on: ubuntu-latest
62-
needs: build
63-
if: ${{ github.repository_owner == 'OpenShock' && github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'master' }}
107+
needs: promote-image
108+
if: ${{ github.ref_type == 'branch' && github.event_name != 'pull_request' && github.ref_name == 'master' }}
64109
environment: production
65-
66110
steps:
67-
- uses: actions/checkout@v5
68-
with:
69-
sparse-checkout: |
70-
.github
71-
72-
- uses: ./.github/actions/kubernetes-rollout-restart
111+
- name: Send repository dispatch
112+
uses: peter-evans/repository-dispatch@v4
73113
with:
74-
apiurl: ${{ secrets.KUBERNETES_APIURL }}
75-
token: ${{ secrets.KUBERNETES_TOKEN }}
76-
deployments: ${{ vars.DEPLOYMENT_NAMES }}
77-
ts-oauth-client-id: ${{ secrets.TS_OAUTH_CLIENT_ID }}
78-
ts-oauth-secret: ${{ secrets.TS_OAUTH_SECRET }}
114+
token: ${{ secrets.GITOPS_PAT }}
115+
repository: openshock/kubernetes-cluster-gitops
116+
event-type: update-desktop-repository-server-prod
117+
client-payload: |
118+
{
119+
"tag": "${{ inputs.tag-prefix || 'rn' }}-${{ github.run_number }}-a${{ github.run_attempt }}"
120+
}

DesktopRepositoryServer/DesktopRepositoryServer.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,8 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22
<PropertyGroup>
3-
<TargetFramework>net10.0</TargetFramework>
4-
<ImplicitUsings>enable</ImplicitUsings>
5-
<Nullable>enable</Nullable>
63
<AssemblyName>OpenShock.Desktop.RepositoryServer</AssemblyName>
74
<RootNamespace>OpenShock.Desktop.RepositoryServer</RootNamespace>
8-
<Company>OpenShock</Company>
95
<Product>Desktop.RepositoryServer</Product>
10-
<AssemblyVersion>1.0.0</AssemblyVersion>
11-
<FileVersion>1.0.0</FileVersion>
12-
<UserSecretsId>1e9d69ec-a751-45af-9dd2-312cc9964162</UserSecretsId>
136
</PropertyGroup>
147
<ItemGroup>
158
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" />

DesktopRepositoryServer/appsettings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"Microsoft.Hosting.Lifetime": "Information",
2626
"Microsoft.AspNetCore.Hosting.Diagnostics": "Warning",
2727
"Serilog.AspNetCore.RequestLoggingMiddleware": "Information",
28+
"OpenShock.Desktop.RepositoryServer.AuthenticationHandlers": "Warning",
2829
"OpenShock": "Information"
2930
}
3031
},

Directory.Packages.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
<PropertyGroup>
33
<!-- Enable central package management, https://learn.microsoft.com/en-us/nuget/consume-packages/Central-Package-Management -->
44
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
5+
<TargetFramework>net10.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<Company>OpenShock</Company>
9+
<AssemblyVersion>1.0.0</AssemblyVersion>
10+
<FileVersion>1.0.0</FileVersion>
11+
<UserSecretsId>1e9d69ec-a751-45af-9dd2-312cc9964162</UserSecretsId>
512
</PropertyGroup>
613
<ItemGroup>
714
<PackageVersion Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />

Dockerfile

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,17 @@ FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine AS build
22
WORKDIR /src
33

44
COPY --link DesktopRepositoryServer/*.csproj DesktopRepositoryServer/
5+
COPY --link *.props .
56
RUN dotnet restore DesktopRepositoryServer/DesktopRepositoryServer.csproj
67

78
COPY --link DesktopRepositoryServer/. DesktopRepositoryServer/
89

9-
RUN dotnet build --no-restore -c Release DesktopRepositoryServer/DesktopRepositoryServer.csproj
10-
11-
# test-build builds the test project
12-
FROM build AS test-build
13-
14-
COPY --link DesktopRepositoryServer.Tests/*.csproj tests/
15-
WORKDIR /src/tests
16-
RUN dotnet restore
17-
18-
COPY --link DesktopRepositoryServer.Tests/ .
19-
RUN dotnet build --no-restore
20-
21-
22-
# test-entrypoint exposes tests as the default executable for the stage
23-
FROM test-build AS test
24-
ENTRYPOINT ["dotnet", "test", "--no-build", "--logger:trx"]
25-
26-
# publish builds and publishes complexapp
27-
FROM build AS publish
28-
WORKDIR /src/DesktopRepositoryServer
29-
RUN dotnet publish --no-restore -o /app
30-
10+
RUN dotnet publish --no-restore -c Release DesktopRepositoryServer/DesktopRepositoryServer.csproj -o /app
3111

3212
# final is the final runtime stage for running the app
3313
FROM mcr.microsoft.com/dotnet/aspnet:10.0-alpine AS final
3414
WORKDIR /app
15+
3516
COPY --link --from=publish /app .
3617
COPY appsettings.Container.json /app/appsettings.Container.json
3718
COPY entrypoint.sh /entrypoint.sh

0 commit comments

Comments
 (0)