You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"Name": "Docker - Build and Push an Image to Dockerhub",
4
+
"Description": "Creates and pushes an Docker Image.\n\n- Requires the Docker infrastructure.",
5
+
"ActionType": "Octopus.Script",
6
+
"Version": 1,
7
+
"CommunityActionTemplateId": null,
8
+
"Packages": [],
9
+
"Properties": {
10
+
"Octopus.Action.Script.ScriptBody": "# Get the parameters.\n$appLocation = $OctopusParameters['DockerfileLocation']\n$dockerFile = $OctopusParameters['DockerFile']\n$imageName = $OctopusParameters['ImageName']\n$tag = $OctopusParameters['ImageTag']\n$dockerUsername = $OctopusParameters['DockerUsername']\n$dockerPassword = $OctopusParameters['DockerPassword']\n\n# Check the parameters.\nif (-NOT $dockerUsername) { throw \"You must enter a value for 'Username'.\" }\nif (-NOT $dockerPassword) { throw \"You must enter a value for 'Password'.\" }\nif (-NOT $imageName) { throw \"You must enter a value for 'Image Name'.\" }\nif (-NOT $tag) { throw \"You must enter a value for 'Image Tag'.\" }\nif (-NOT $appLocation) { throw \"You must enter a value for 'Dockerfile Location'.\" }\n\n# If the Dockerfile parameter is not empty, save it to the file.\nif ($dockerFile) \n{\n Write-Output 'Saving the Dockerfile'\n $path = Join-Path $appLocation 'Dockerfile'\n Set-Content -Path $path -Value $dockerFile -Force\n}\n\n# If the tag parameter is empty, set it as latest.\nif (-NOT $tag) \n{\n $tag = 'latest'\n}\n\n# Prepare the final image name with the tag.\n$imageName += ':' + $tag\n\n# Create the docker image\nWrite-Output 'Building the Docker Image'\nsudo docker build -t $imageName .\n\n# Upload to DockerHub\nWrite-Output 'Pushing the Docker Image to DockerHub'\nsudo docker login --username=$dockerUsername --password=$dockerPassword\nsudo docker push $imageName",
11
+
"Octopus.Action.Script.Syntax": "PowerShell",
12
+
"Octopus.Action.Script.ScriptSource": "Inline"
13
+
},
14
+
"Parameters": [
15
+
{
16
+
"Id": "a3d56a5f-4a3e-4eec-ac75-b27d96a4206a",
17
+
"Name": "DockerUsername",
18
+
"Label": "Docker Username",
19
+
"HelpText": "The username used to login to DockerHub",
20
+
"DefaultValue": "",
21
+
"DisplaySettings": {
22
+
"Octopus.ControlType": "SingleLineText"
23
+
}
24
+
},
25
+
{
26
+
"Id": "3022543d-41ec-4b5a-9b9e-5072d33522db",
27
+
"Name": "DockerPassword",
28
+
"Label": "Docker Password",
29
+
"HelpText": "The password used to login to DockerHub",
30
+
"DefaultValue": "",
31
+
"DisplaySettings": {
32
+
"Octopus.ControlType": "Sensitive"
33
+
}
34
+
},
35
+
{
36
+
"Id": "4c0e2b19-3307-49c0-a202-4baf2a066558",
37
+
"Name": "DockerfileLocation",
38
+
"Label": "Dockerfile Location",
39
+
"HelpText": "Location on the deployment target where the Dockerfile should be saved.",
40
+
"DefaultValue": "",
41
+
"DisplaySettings": {
42
+
"Octopus.ControlType": "SingleLineText"
43
+
}
44
+
},
45
+
{
46
+
"Id": "aaee54ac-2470-4d38-90b6-799f0b9aa4d8",
47
+
"Name": "DockerFile",
48
+
"Label": "Dockerfile",
49
+
"HelpText": "The Dockerfile definition. If the Dockerfile is part of the package leave it blank",
50
+
"DefaultValue": "",
51
+
"DisplaySettings": {
52
+
"Octopus.ControlType": "MultiLineText"
53
+
}
54
+
},
55
+
{
56
+
"Id": "9e8d0131-26a0-4c51-bb70-758eed70f252",
57
+
"Name": "ImageName",
58
+
"Label": "Image Name",
59
+
"HelpText": "The image name in DockerHub",
60
+
"DefaultValue": "",
61
+
"DisplaySettings": {
62
+
"Octopus.ControlType": "SingleLineText"
63
+
}
64
+
},
65
+
{
66
+
"Id": "25df2def-98ab-45b4-8805-670aa08b297e",
67
+
"Name": "ImageTag",
68
+
"Label": "Image Tag",
69
+
"HelpText": "The image tag. Leave it blank for 'latest'",
0 commit comments