-
Notifications
You must be signed in to change notification settings - Fork 2
131 lines (113 loc) · 5.21 KB
/
octopus-cli.yml
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
name: octopus-cli Docker image for GitLab
on:
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
jobs:
get-octopus-cli-version:
runs-on: windows-latest
outputs:
VERSION: ${{ steps.choco.outputs.VERSION }}
CONTINUE: ${{ steps.choco.outputs.CONTINUE }}
steps:
- uses: actions/checkout@v3
- id: choco
name: Compare latest version with container
run: |
$chocoInformationRaw = choco info octopus-cli --limitoutput
$versionOutput = ($chocoInformationRaw.Split("|"))[1]
[System.Version]$version = $null
$versionParsed = [System.Version]::TryParse($versionOutput, [ref]$version)
if(-not $versionParsed) {
Write-Host "Unable to parse '$versionOutput' as a valid version. Won't continue"
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else {
$versionToCompare = "$($version.Major).$($version.Minor).$($version.Build)"
Write-Host "Parsed version as $versionToCompare"
echo "VERSION=$versionToCompare" >> $env:GITHUB_OUTPUT
$response = try {
$repositoryTags = Invoke-RestMethod "https://registry.hub.docker.com/v2/repositories/octopuslabs/gitlab-octopus-cli/tags"
Write-Host "Retrieval successful!"
} catch [System.Net.WebException] {
$_.Exception.Response
Write-Host "Retrieval failed!!"
}
if ($null -eq $response)
{
$matchingTag = $repositoryTags.results | Where-Object {$_.Name -eq $versionToCompare}
if ($null -ne $matchingTag)
{
Write-Host "Docker container already has latest version."
echo "CONTINUE=No" >> $env:GITHUB_OUTPUT
}
else
{
Write-Host "vNext Octopus CLI has been updated, create new image."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
else
{
if ($response.StatusCode.value__ -eq 404)
{
Write-Host "No tags exist for repo, assuming first build."
echo "CONTINUE=Yes" >> $env:GITHUB_OUTPUT
}
}
}
shell: powershell
# This workflow contains a single job called "build"
build-linux:
# define needs
needs: [get-octopus-cli-version]
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
# Login to docker
- name: Docker Hub login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username $USERNAME --password "$PASSWORD"
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
# Build ubuntu images
- name: Build the alpine docker image
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: docker build ./octopus-cli/alpine --build-arg OCTOPUS_CLI_VERSION=${{ needs.get-octopus-cli-version.outputs.VERSION }} --tag octopuslabs/gitlab-octopus-cli:${{ needs.get-octopus-cli-version.outputs.VERSION }}-alpine --tag octopuslabs/gitlab-octopus-cli:latest-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push the alpine image
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker push octopuslabs/gitlab-octopus-cli:$VERSION_NUMBER-alpine
docker push octopuslabs/gitlab-octopus-cli:latest-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
build-docker-manifest:
needs: [build-linux, get-octopus-cli-version]
runs-on: ubuntu-latest
steps:
- name: Docker hub login
env:
USERNAME: ${{ secrets.DOCKER_HUB_USER }}
PASSWORD: ${{ secrets.DOCKER_HUB_PAT }}
run: docker login --username $USERNAME --password "$PASSWORD"
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Build manifests
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest create octopuslabs/gitlab-octopus-cli:latest octopuslabs/gitlab-octopus-cli:latest-alpine
docker manifest create octopuslabs/gitlab-octopus-cli:$VERSION_NUMBER octopuslabs/gitlab-octopus-cli:$VERSION_NUMBER-alpine
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}
- name: Push manifests
env:
VERSION_NUMBER: ${{ needs.get-octopus-cli-version.outputs.VERSION }}
run: |
docker manifest push octopuslabs/gitlab-octopus-cli:latest
docker manifest push octopuslabs/gitlab-octopus-cli:$VERSION_NUMBER
if: ${{ needs.get-octopus-cli-version.outputs.CONTINUE == 'Yes' }}