/
docker-create-and-push-image.json
76 lines (76 loc) · 3.52 KB
/
docker-create-and-push-image.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{
"Id": "3ff1e0ae-0336-41e3-905a-a1f10f4bb1cf",
"Name": "Docker - Create and Push Image",
"Description": "Creates and pushes an Docker Image.\n\n- Requires the Docker infrastructure.",
"ActionType": "Octopus.Script",
"Version": 1,
"Properties": {
"Octopus.Action.Script.ScriptBody": "# Get the parameters.\r\n$appLocation = $OctopusParameters['ApplicationLocation']\r\n$dockerFile = $OctopusParameters['DockerFile']\r\n$imageName = $OctopusParameters['ImageName']\r\n$tag = $OctopusParameters['ImageTag']\r\n$dockerUsername = $OctopusParameters['DockerUsername']\r\n$dockerPassword = $OctopusParameters['DockerPassword']\r\n\r\n# Check the parameters.\r\nif (-NOT $dockerUsername) { throw \"You must enter a value for 'Username'.\" }\r\nif (-NOT $dockerPassword) { throw \"You must enter a value for 'Password'.\" }\r\nif (-NOT $imageName) { throw \"You must enter a value for 'Image Name'.\" }\r\nif (-NOT $appLocation) { throw \"You must enter a value for 'Application Location'.\" }\r\n\r\n# If the Dockerfile parameter is not empty, save it to the file.\r\nif ($dockerFile) \r\n{\r\n Write-Output 'Saving the Dockerfile'\r\n $path = Join-Path $appLocation 'Dockerfile'\r\n Set-Content -Path $path -Value $dockerFile -Force\r\n}\r\n\r\n# If the tag parameter is empty, set it as latest.\r\nif (-NOT $tag) \r\n{\r\n $tag = 'latest'\r\n}\r\n\r\n# Prepare the final image name with the tag.\r\n$imageName += ':' + $tag\r\n\r\n# Create the docker image\r\nWrite-Output 'Building the Docker Image'\r\ndocker build -t $imageName $appLocation\r\n\r\n# Upload to DockerHub\r\nWrite-Output 'Pushing the Docker Image to DockerHub'\r\ndocker login -u $dockerUsername -p $dockerPassword\r\ndocker push $imageName",
"Octopus.Action.Script.Syntax": "PowerShell"
},
"SensitiveProperties": {},
"Parameters": [
{
"Name": "DockerUsername",
"Label": "Docker Username",
"HelpText": "The username used to login to DockerHub",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DockerPassword",
"Label": "Docker Password",
"HelpText": "The password used to login to DockerHub",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "Sensitive"
}
},
{
"Name": "ApplicationLocation",
"Label": "Application Location",
"HelpText": "The application location, used to build the Docker image",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "DockerFile",
"Label": "Dockerfile",
"HelpText": "The Dockerfile definition. If the Dockerfile is part of the package leave it blank",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "MultiLineText"
}
},
{
"Name": "ImageName",
"Label": "Image Name",
"HelpText": "The image name in DockerHub",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
},
{
"Name": "ImageTag",
"Label": "Image Tag",
"HelpText": "The image tag. Leave it blank for 'latest'",
"DefaultValue": null,
"DisplaySettings": {
"Octopus.ControlType": "SingleLineText"
}
}
],
"LastModifiedOn": "2017-02-03T10:49:13.997Z",
"LastModifiedBy": "joaoasrosa",
"$Meta": {
"ExportedAt": "2017-02-03T10:49:13.997Z",
"OctopusVersion": "3.3.27",
"Type": "ActionTemplate"
},
"Category": "docker"
}