Skip to content

Commit 191c769

Browse files
authored
Merge pull request #13 from rubberduck-vba/p0
Implement caching and CD pipelines for test and prod sites
2 parents 01db4d2 + d9a5d79 commit 191c769

24 files changed

+728
-329
lines changed

.github/workflows/dotnet-cd-prod.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: prod-deploy
2+
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: dependency caching
17+
uses: actions/cache@v4
18+
with:
19+
path: ~/.nuget/packages
20+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
21+
restore-keys: |
22+
${{ runner.os }}-nuget-
23+
24+
- name: dotnet build
25+
run: dotnet build rubberduckvba.Server --configuration Release
26+
27+
- name: dotnet publish
28+
run: dotnet publish "rubberduckvba.Server\rubberduckvba.Server.csproj" --configuration Release --output ${{env.DOTNET_ROOT}}\pub
29+
30+
- name: upload artifacts
31+
uses: actions/upload-artifact@v4
32+
with:
33+
name: pub
34+
path: ${{env.DOTNET_ROOT}}\pub
35+
36+
deploy:
37+
runs-on: self-hosted
38+
needs: build
39+
steps:
40+
- name: download artifacts
41+
uses: actions/download-artifact@v4
42+
with:
43+
name: pub
44+
45+
- name: deploy iis site
46+
run: |
47+
stop-webapppool -name "api-prod"
48+
stop-iissite -name api-prod -confirm: $false
49+
copy-item C:/pub/* C:/inetpub/wwwroot/rubberduckvba.com -Recurse -Force
50+
copy-item C:/inetpub/appsettings.prod.json C:/inetpub/wwwroot/rubberduckvba.com/appsettings.json -Force
51+
copy-item C:/inetpub/__Web.config C:/inetpub/wwwroot/rubberduckvba.com/wwwroot/browser/Web.config -Force
52+
start-webapppool api-prod
53+
start-iissite api-prod

.github/workflows/dotnet-cd.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ permissions:
1010

1111
jobs:
1212
build:
13-
runs-on: self-hosted
13+
runs-on: ubuntu-latest
1414

1515
steps:
1616
- uses: actions/checkout@v4
1717

18-
- name: Set up dependency caching for faster builds
18+
- name: dependency caching
1919
uses: actions/cache@v4
2020
with:
2121
path: ~/.nuget/packages
@@ -29,14 +29,27 @@ jobs:
2929
- name: dotnet publish
3030
run: dotnet publish "rubberduckvba.Server\rubberduckvba.Server.csproj" --configuration Release --output ${{env.DOTNET_ROOT}}\pub
3131

32+
- name: upload artifacts
33+
uses: actions/upload-artifact@v4
34+
with:
35+
name: pub
36+
path: ${{env.DOTNET_ROOT}}\pub
37+
3238
deploy:
3339
runs-on: self-hosted
3440
needs: build
3541
steps:
42+
- name: download artifacts
43+
uses: actions/download-artifact@v4
44+
with:
45+
name: pub
46+
3647
- name: deploy iis site
3748
run: |
3849
stop-webapppool -name "rubberduckvba"
3950
stop-iissite -name api -confirm: $false
40-
copy-item C:/pub/* C:/inetpub/wwwroot -Recurse -Force
51+
copy-item C:/pub/* C:/inetpub/wwwroot/test.rubberduckvba.com -Recurse -Force
52+
copy-item C:/inetpub/appsettings.test.json C:/inetpub/wwwroot/test.rubberduckvba.com/appsettings.json -Force
53+
copy-item C:/inetpub/__Web.config C:/inetpub/wwwroot/test.rubberduckvba.com/wwwroot/browser/Web.config -Force
4154
start-webapppool rubberduckvba
4255
start-iissite api

rubberduckvba.Server/Api/Downloads/DownloadsController.cs

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,54 @@
66
namespace rubberduckvba.Server.Api.Downloads;
77

88

9-
[ApiController]
109
[AllowAnonymous]
11-
public class DownloadsController(IContentCacheService cache, IRubberduckDbService db) : Controller
10+
public class DownloadsController : RubberduckApiController
1211
{
12+
private readonly CacheService cache;
13+
private readonly IRubberduckDbService db;
14+
15+
public DownloadsController(CacheService cache, IRubberduckDbService db, ILogger<DownloadsController> logger)
16+
: base(logger)
17+
{
18+
this.cache = cache;
19+
this.db = db;
20+
}
21+
1322
[HttpGet("downloads")]
14-
public async Task<ActionResult<IEnumerable<AvailableDownload>>> GetAvailableDownloadsAsync()
23+
public IActionResult GetAvailableDownloadsAsync()
1524
{
16-
var cacheKey = $"{nameof(GetAvailableDownloadsAsync)}";
17-
if (!cache.TryGetValue(cacheKey, out IEnumerable<AvailableDownload> downloads))
25+
return GuardInternalAction(() =>
1826
{
19-
var tags = (await db.GetLatestTagsAsync(RepositoryId.Rubberduck)).ToImmutableArray();
20-
var main = tags[0];
21-
var next = tags[1];
27+
AvailableDownload[] result = [];
28+
if (!cache.TryGetAvailableDownloads(out var cached))
29+
{
30+
var tags = db.GetLatestTagsAsync(RepositoryId.Rubberduck).GetAwaiter().GetResult().ToImmutableArray();
31+
var main = tags[0];
32+
var next = tags[1];
33+
34+
var pdfStyleGuide = new AvailableDownload
35+
{
36+
Name = "Rubberduck Style Guide (PDF)",
37+
Title = "Free (pay what you want) PDF download",
38+
Kind = "pdf",
39+
DownloadUrl = "https://ko-fi.com/s/d91bfd610c"
40+
};
2241

23-
var pdfStyleGuide = new AvailableDownload
42+
result =
43+
[
44+
AvailableDownload.FromTag(main),
45+
AvailableDownload.FromTag(next),
46+
pdfStyleGuide
47+
];
48+
49+
cache.Invalidate(result);
50+
}
51+
else
2452
{
25-
Name = "Rubberduck Style Guide (PDF)",
26-
Title = "Free (pay what you want) PDF download",
27-
Kind = "pdf",
28-
DownloadUrl = "https://ko-fi.com/s/d91bfd610c"
29-
};
30-
31-
downloads = [
32-
AvailableDownload.FromTag(main),
33-
AvailableDownload.FromTag(next),
34-
pdfStyleGuide
35-
];
36-
37-
cache.SetValue(cacheKey, downloads);
38-
}
39-
40-
return downloads.Any() ? Ok(downloads) : NoContent();
53+
result = cached ?? [];
54+
}
55+
56+
return result.Any() ? Ok(result) : NoContent();
57+
});
4158
}
4259
}

0 commit comments

Comments
 (0)