Skip to content

Commit 5045240

Browse files
2 parents c418579 + f516667 commit 5045240

6 files changed

Lines changed: 116 additions & 8 deletions

File tree

Dockerfile

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
FROM golang:latest
22

3+
RUN mkdir /build
34
WORKDIR /build
45

5-
COPY ./main /build
6+
RUN export GO111MODULE=on
7+
RUN go get github.com/AdminTurnedDevOps/GoWebAPI/main
8+
RUN cd /build && git clone https://github.com/AdminTurnedDevOps/GoWebAPI.git
69

7-
EXPOSE 8080
10+
RUN cd /build/GoWebAPI/main && go build
811

9-
RUN go build -o main .
12+
EXPOSE 8080
1013

11-
ENTRYPOINT [ "./main" ]
14+
ENTRYPOINT [ "/build/GoWebAPI/main/main" ]

azure-pipelines.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
trigger:
2+
- master
3+
4+
pool:
5+
vmImage: 'ubuntu-latest'
6+
7+
steps:
8+
- task: CopyFiles@2
9+
inputs:
10+
Contents: '**'
11+
TargetFolder: '$(Build.ArtifactStagingDirectory)'
12+
13+
- task: PublishBuildArtifacts@1
14+
inputs:
15+
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
16+
ArtifactName: 'drop'
17+
18+
- task: GoTool@0
19+
inputs:
20+
version: '1.15'
21+
22+
- task: Go@0
23+
inputs:
24+
command: 'build'
25+
workingDirectory: '$(Build.ArtifactStagingDirectory)/main'

instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
Run the following commands:
22

33
1. docker build -t golangwebapi .
4-
2. docker run -tid golangwebapi -p 8080:8080
4+
2. docker run -p 8080:8080 -tid golangwebapi

main/go.mod

Lines changed: 0 additions & 3 deletions
This file was deleted.

main/main

-6.16 MB
Binary file not shown.

step-template.json

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"Id": "3aa47b93-e859-4a8a-946d-13921f3c7197",
3+
"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'",
70+
"DefaultValue": "",
71+
"DisplaySettings": {
72+
"Octopus.ControlType": "SingleLineText"
73+
}
74+
}
75+
],
76+
"$Meta": {
77+
"ExportedAt": "2020-09-25T20:37:57.314Z",
78+
"OctopusVersion": "2020.4.0",
79+
"Type": "ActionTemplate"
80+
},
81+
"LastModifiedBy": "Your GitHub Username",
82+
"Category": "other"
83+
}

0 commit comments

Comments
 (0)