Skip to content

Commit 4855c8f

Browse files
committed
Fixed docker deployments
1 parent 9c70946 commit 4855c8f

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,3 +113,5 @@ src/GitVersionTfsTask/*.js
113113
/tools
114114
/*.zip
115115
GitVersion.CommandLine/*/
116+
117+
releaseArtifacts

appveyor.deploy.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
1+
image: Visual Studio 2017
2+
3+
environment:
4+
DOCKER_USERNAME:
5+
secure: EbFuNVc5k/p9AiaBmS839D4GqsNaMlJ3djyRR5b2fjM=
6+
DOCKER_PASSWORD:
7+
secure: kweTIFTVyAVyKlvcIvgffpNa6qK8wyWAekVgue8WFqI=
8+
19
install:
2-
npm i -g tfx-cli
10+
- npm i -g tfx-cli
11+
- docker version
312

413
assembly_info:
514
patch: false

deploy.cake

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#addin "Cake.Json"
2+
#addin "Cake.Docker"
23

34
var target = Argument("target", "Deploy");
5+
var tagOverride = Argument("TagOverride", "");
46

57
using System.Net;
68
using System.Linq;
@@ -25,6 +27,13 @@ string Get(string url)
2527
Task("EnsureRequirements")
2628
.Does(() =>
2729
{
30+
// This allows us to test deployments locally..
31+
if (!string.IsNullOrWhiteSpace(tagOverride))
32+
{
33+
tag = tagOverride;
34+
return;
35+
}
36+
2837
if (!AppVeyor.IsRunningOnAppVeyor)
2938
throw new Exception("Deployment should happen via appveyor");
3039

@@ -42,8 +51,12 @@ Task("UpdateVersionInfo")
4251
.IsDependentOn("EnsureRequirements")
4352
.Does(() =>
4453
{
45-
tag = AppVeyor.Environment.Repository.Tag.Name;
46-
AppVeyor.UpdateBuildVersion(tag);
54+
// Will not be empty if overriden
55+
if (tag == "")
56+
{
57+
tag = AppVeyor.Environment.Repository.Tag.Name;
58+
AppVeyor.UpdateBuildVersion(tag);
59+
}
4760
});
4861

4962
Task("DownloadGitHubReleaseArtifacts")
@@ -180,23 +193,43 @@ Task("Publish-DockerImage")
180193
.IsDependentOn("DownloadGitHubReleaseArtifacts")
181194
.Does(() =>
182195
{
196+
var username = EnvironmentVariable("DOCKER_USERNAME");
197+
var password = EnvironmentVariable("DOCKER_PASSWORD");
198+
if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password))
199+
{
200+
Warning("Skipping docker publish due to missing credentials");
201+
return;
202+
}
203+
183204
var returnCode = StartProcess("docker", new ProcessSettings
184205
{
185-
Arguments = "build . --build-arg GitVersionZip=" + artifactLookup["zip"] + " --tag gittools/gitversion"
206+
Arguments = "build . --build-arg GitVersionZip=" + artifactLookup["zip"] + " --tag gittools/gitversion:" + tag
186207
});
187208
if (returnCode != 0) {
188209
Information("Publish-DockerImage Task failed to build image, but continuing with next Task...");
189210
publishingError = true;
211+
return;
212+
}
213+
214+
returnCode = StartProcess("docker", new ProcessSettings
215+
{
216+
Arguments = "run -v " + System.IO.Directory.GetCurrentDirectory() + ":/repo gittools/gitversion:" + tag
217+
});
218+
if (returnCode != 0) {
219+
Information("Publish-DockerImage Task failed to run built image, but continuing with next Task...");
220+
publishingError = true;
221+
return;
190222
}
191223

192224
// Login to dockerhub
193225
returnCode = StartProcess("docker", new ProcessSettings
194226
{
195-
Arguments = "login -u=\"" + EnvironmentVariable("DOCKER_USERNAME") +"\" -p=\"" + EnvironmentVariable("DOCKER_PASSWORD") +"\""
227+
Arguments = "login -u=\"" + username +"\" -p=\"" + password +"\""
196228
});
197229
if (returnCode != 0) {
198230
Information("Publish-DockerImage Task failed to login, but continuing with next Task...");
199231
publishingError = true;
232+
return;
200233
}
201234

202235
// Publish Tag
@@ -207,10 +240,19 @@ Task("Publish-DockerImage")
207240
if (returnCode != 0) {
208241
Information("Publish-DockerImage Task failed push version tag, but continuing with next Task...");
209242
publishingError = true;
243+
return;
210244
}
211245

212246
// Publish latest
213247
returnCode = StartProcess("docker", new ProcessSettings
248+
{
249+
Arguments = "tag gittools/gitversion:" + tag + " gittools/gitversion:latest"
250+
});
251+
if (returnCode != 0) {
252+
Information("Publish-DockerImage Task failed latest tag, but continuing with next Task...");
253+
publishingError = true;
254+
}
255+
returnCode = StartProcess("docker", new ProcessSettings
214256
{
215257
Arguments = "push gittools/gitversion:latest"
216258
});

0 commit comments

Comments
 (0)