Skip to content

Commit 7646adf

Browse files
authored
Merge pull request #297 from ChangemakerStudios/feature/docker-build
Add Docker build and multi-platform support to GitHub Actions
2 parents 95f9dc3 + 25827f7 commit 7646adf

4 files changed

Lines changed: 67 additions & 84 deletions

File tree

.github/workflows/build.yml

Lines changed: 48 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ jobs:
2121
build:
2222
name: Build Papercut SMTP
2323
runs-on: windows-2022
24+
permissions:
25+
contents: write
2426

2527
steps:
2628
- name: Checkout code
@@ -63,38 +65,62 @@ jobs:
6365
path: releases/*
6466
if-no-files-found: warn
6567

66-
- name: Create GitHub Release (master only)
68+
- name: Attach Service artifacts to release (master only)
6769
if: github.ref == 'refs/heads/master' && github.event_name == 'push'
6870
uses: softprops/action-gh-release@v2
6971
with:
7072
tag_name: v${{ steps.gitversion.outputs.semVer }}
71-
name: Release v${{ steps.gitversion.outputs.semVer }}
72-
body: |
73-
## Release Notes
74-
75-
This is an automated release for Papercut SMTP v${{ steps.gitversion.outputs.semVer }}.
76-
77-
See [ReleaseNotes.md](https://github.com/ChangemakerStudios/Papercut-SMTP/blob/master/ReleaseNotes.md) for details.
78-
draft: false
79-
prerelease: false
80-
files: releases/*
73+
files: releases/Papercut.Smtp.Service.*.zip
74+
fail_on_unmatched_files: false
8175
env:
8276
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8377

84-
- name: Create Pre-release (develop only)
78+
- name: Attach Service artifacts to pre-release (develop only)
8579
if: github.ref == 'refs/heads/develop' && github.event_name == 'push'
8680
uses: softprops/action-gh-release@v2
8781
with:
8882
tag_name: v${{ steps.gitversion.outputs.semVer }}
89-
name: Pre-release v${{ steps.gitversion.outputs.semVer }}
90-
body: |
91-
## Development Pre-release
92-
93-
This is an automated pre-release build from the develop branch.
94-
95-
**Version:** ${{ steps.gitversion.outputs.fullSemVer }}
96-
draft: false
97-
prerelease: true
98-
files: releases/*
83+
files: releases/Papercut.Smtp.Service.*.zip
84+
fail_on_unmatched_files: false
9985
env:
10086
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
87+
88+
- name: Set up Docker Buildx
89+
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.event_name == 'push'
90+
uses: docker/setup-buildx-action@v3
91+
92+
- name: Log in to Docker Hub
93+
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.event_name == 'push'
94+
uses: docker/login-action@v3
95+
with:
96+
username: ${{ secrets.DOCKER_USERNAME }}
97+
password: ${{ secrets.DOCKER_PASSWORD }}
98+
99+
- name: Extract Docker metadata
100+
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.event_name == 'push'
101+
id: meta
102+
uses: docker/metadata-action@v5
103+
with:
104+
images: changemakerstudios/papercut-smtp
105+
tags: |
106+
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
107+
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/develop' }}
108+
type=raw,value=${{ steps.gitversion.outputs.fullSemVer }},enable=${{ github.ref == 'refs/heads/develop' }}
109+
type=semver,pattern={{version}},value=${{ steps.gitversion.outputs.semVer }},enable=${{ github.ref == 'refs/heads/master' }}
110+
type=semver,pattern={{major}}.{{minor}},value=${{ steps.gitversion.outputs.semVer }},enable=${{ github.ref == 'refs/heads/master' }}
111+
112+
- name: Build and push Docker image
113+
if: (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.event_name == 'push'
114+
uses: docker/build-push-action@v5
115+
with:
116+
context: .
117+
push: true
118+
tags: ${{ steps.meta.outputs.tags }}
119+
labels: ${{ steps.meta.outputs.labels }}
120+
build-args: |
121+
BUILD_VERSION=${{ steps.gitversion.outputs.fullSemVer }}
122+
BUILD_DATE=${{ github.event.repository.updated_at }}
123+
VCS_REF=${{ github.sha }}
124+
platforms: linux/amd64,linux/arm64
125+
cache-from: type=gha
126+
cache-to: type=gha,mode=max

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ src/Papercut.UI/Releases
2424
publish
2525
Releases
2626
.angular
27+
settings.local.json

build.cake

Lines changed: 17 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
#tool "nuget:?package=System.Configuration.ConfigurationManager&version=4.5.0"
33
#tool "nuget:?package=MarkdownSharp&version=2.0.5"
4-
#tool "nuget:?package=MimekitLite&version=4.5.0"
4+
#tool "nuget:?package=MimekitLite&version=4.14.0"
55
#tool "nuget:?package=NUnit.ConsoleRunner&version=3.17.0"
66
#tool "nuget:?package=OpenCover&version=4.7.1221"
77

8-
#tool "dotnet:?package=GitVersion.Tool&version=5.12.0"
9-
#tool "dotnet:?package=vpk&version=0.0.359"
8+
#tool "dotnet:?package=GitVersion.Tool&version=6.4.0"
9+
#tool "dotnet:?package=vpk&version=0.0.1298"
1010

1111
#addin "nuget:?package=Cake.FileHelpers&version=6.1.3"
1212
#addin "nuget:?package=Cake.Incubator&version=8.0.0"
@@ -28,22 +28,16 @@ var configuration = Argument("configuration", "Release");
2828
var target = Argument("target", "All");
2929
GitVersion versionInfo = GitVersion(new GitVersionSettings { OutputType = GitVersionOutput.Json });
3030

31-
var isMasterBranch = false;
32-
var isDevelopBranch = false;
33-
var hasGithubToken = false;
34-
string? githubToken = null;
31+
var isRunningInGitHubActions = !string.IsNullOrEmpty(EnvironmentVariable("GITHUB_ACTIONS"));
32+
var branchName = EnvironmentVariable("GITHUB_REF_NAME") ?? versionInfo.BranchName;
33+
var isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals("master", branchName);
34+
var isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", branchName);
35+
var githubToken = EnvironmentVariable<string?>("GITHUB_TOKEN", null);
36+
var hasGithubToken = !string.IsNullOrEmpty(githubToken);
3537

36-
if (AppVeyor.IsRunningOnAppVeyor)
38+
if (isRunningInGitHubActions)
3739
{
38-
Information($"Building Branch '{BuildSystem.AppVeyor.Environment.Repository.Branch}'...");
39-
isMasterBranch = StringComparer.OrdinalIgnoreCase.Equals("master", BuildSystem.AppVeyor.Environment.Repository.Branch);
40-
isDevelopBranch = StringComparer.OrdinalIgnoreCase.Equals("develop", BuildSystem.AppVeyor.Environment.Repository.Branch);
41-
githubToken = EnvironmentVariable<string?>("github-token", null);
42-
}
43-
44-
if (!string.IsNullOrEmpty(githubToken))
45-
{
46-
hasGithubToken = true;
40+
Information($"Building Branch '{branchName}'...");
4741
}
4842

4943
var channelPostfix = isMasterBranch ? "-stable" : isDevelopBranch ? "-dev" : "-alpha";
@@ -54,11 +48,7 @@ var channelPostfix = isMasterBranch ? "-stable" : isDevelopBranch ? "-dev" : "-a
5448
Setup(ctx =>
5549
{
5650
Information("Running tasks...");
57-
58-
if (AppVeyor.IsRunningOnAppVeyor)
59-
{
60-
AppVeyor.UpdateBuildVersion(versionInfo.SemVer);
61-
}
51+
Information($"Version: {versionInfo.SemVer}");
6252
});
6353

6454
Teardown(ctx => Information("Finished running tasks."));
@@ -112,23 +102,6 @@ Task("Restore")
112102
DotNetRestore("./Papercut.sln");
113103
});
114104

115-
Task("DownloadReleases")
116-
.WithCriteria(hasGithubToken)
117-
.IsDependentOn("Restore")
118-
.Does(() =>
119-
{
120-
var arguments = new ProcessArgumentBuilder()
121-
.Append("download").Append("github")
122-
.Append("--repoUrl").Append("https://github.com/ChangemakerStudios/Papercut-SMTP")
123-
.Append("--token").Append(EnvironmentVariable<string>("github-token", ""));
124-
125-
StartProcess("vpk", new ProcessSettings
126-
{
127-
Arguments = arguments
128-
});
129-
})
130-
.OnError(exception => Error(exception));
131-
132105
///////////////////////////////////////////////////////////////////////////////
133106
// BUILD
134107
Task("BuildUI64")
@@ -211,29 +184,29 @@ Task("PackageUI32")
211184
.OnError(exception => Error(exception));
212185

213186
Task("DeployReleases")
214-
.WithCriteria(AppVeyor.IsRunningOnAppVeyor && isMasterBranch && hasGithubToken)
187+
.WithCriteria(isRunningInGitHubActions && isMasterBranch && hasGithubToken)
215188
.Does(() =>
216189
{
217-
Information($"Uploading Papercut SMTP 64-bit Release {GitVersionOutput.BuildServer}");
190+
Information($"Uploading Papercut SMTP 64-bit Release {versionInfo.FullSemVer}");
218191

219192
var uploadParams = new VpkUploadParams
220193
{
221194
Channel = "win-x64" + channelPostfix,
222195
ReleaseDirectory = releasesDirectory,
223-
Token = EnvironmentVariable<string>("github-token", ""),
196+
Token = githubToken ?? "",
224197
Repository = "https://github.com/ChangemakerStudios/Papercut-SMTP",
225198
IsPrelease = !isMasterBranch
226199
};
227200

228201
Velopack.UploadGithub(Context, uploadParams);
229202

230-
Information($"Uploading Papercut SMTP 32-bit Release {GitVersionOutput.BuildServer}");
203+
Information($"Uploading Papercut SMTP 32-bit Release {versionInfo.FullSemVer}");
231204

232205
uploadParams = new VpkUploadParams
233206
{
234207
Channel = "win-x86" + channelPostfix,
235208
ReleaseDirectory = releasesDirectory,
236-
Token = EnvironmentVariable<string>("github-token", ""),
209+
Token = githubToken ?? "",
237210
Repository = "https://github.com/ChangemakerStudios/Papercut-SMTP",
238211
IsPrelease = !isMasterBranch
239212
};
@@ -248,8 +221,6 @@ Task("BuildAndPackServiceWin64")
248221
.Does(() =>
249222
{
250223
CleanDirectory(publishDirectory);
251-
CleanDirectory(releasesDirectory);
252-
253224
var runtime = "win-x64";
254225

255226
var settings = new DotNetPublishSettings
@@ -298,32 +269,17 @@ Task("BuildAndPackServiceWin32")
298269
})
299270
.OnError(exception => Error(exception));
300271

301-
Task("UploadArtifacts")
302-
.WithCriteria(AppVeyor.IsRunningOnAppVeyor)
303-
.IsDependentOn("BuildAndPackServiceWin32")
304-
.Does(() =>
305-
{
306-
foreach (var file in GetFiles(releasesDirectory.ToString() + "/**/*.zip"))
307-
{
308-
Information($"Uploading Artifact to AppVeyor: {file}");
309-
AppVeyor.UploadArtifact(file);
310-
}
311-
})
312-
.OnError(exception => Error(exception));
313-
314272
///////////////////////////////////////////////////////////////////////////////
315273
Task("All")
316274
.IsDependentOn("Clean")
317275
.IsDependentOn("PatchAssemblyInfo")
318276
.IsDependentOn("CreateReleaseNotes")
319-
.IsDependentOn("DownloadReleases")
320277
.IsDependentOn("Restore")
321278
.IsDependentOn("BuildUI32").IsDependentOn("PackageUI32")
322279
.IsDependentOn("BuildUI64").IsDependentOn("PackageUI64")
323280
.IsDependentOn("DeployReleases")
324281
.IsDependentOn("BuildAndPackServiceWin64")
325282
.IsDependentOn("BuildAndPackServiceWin32")
326-
.IsDependentOn("UploadArtifacts")
327283
.OnError(exception => Error(exception));
328284

329285
RunTarget(target);

src/Papercut.UI/Papercut.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<PackageReference Include="Serilog.Sinks.Seq" Version="9.0.0" />
6868
<PackageReference Include="System.Net.Http" Version="4.3.4" />
6969
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
70-
<PackageReference Include="Velopack" Version="0.0.1053" />
70+
<PackageReference Include="Velopack" Version="0.0.1298" />
7171
</ItemGroup>
7272
<ItemGroup>
7373
<Resource Include="Resources\attachment-icon.png" />

0 commit comments

Comments
 (0)