-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathaction.yml
More file actions
129 lines (125 loc) · 5.12 KB
/
action.yml
File metadata and controls
129 lines (125 loc) · 5.12 KB
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
name: "Build and push image to SetOps registry"
description: "Builds the Docker images and pushes it to the SetOps registry while creating a tag for each stage / app combination"
inputs:
setops-organization:
description: The SetOps organization
required: true
setops-project:
description: The SetOps project name
required: true
setops-username:
description: The SetOps username, usually passed in from a Github Actions secret
required: true
setops-password:
description: The SetOps password, usually passed in from a Github Actions secret
required: true
setops-stages:
description: The SetOps stages to publish to, space separated, e.g. "stage1 stage2 stage3"
required: true
setops-apps:
description: The SetOps apps to build and deploy, space separated, e.g. "app1 app2 app3"
required: true
setops-api-domain:
description: The SetOps API domain to connect to
default: "api.setops.co"
required: false
setops-version:
description: "The version of SetOps CLI to install. Instead of a full version string you can also specify a constraint string. Examples are: `<0.1.5`, `~0.1.4`, `0.1.x` (all three installing the latest available 0.1.4 version). Defaults to `latest`."
required: false
image-tag:
description: The tag with which the image(s) should be tagged e.g. v1.1.0 (defaults to commit hash)
default: ${{ github.sha }}
required: false
build-context:
description: The build context / directory where the Dockerfile is located, defaults to '.'
required: false
default: .
build-cache-key-prefix:
description: The cache key used by docker buildx. The complete cache key is concatenated
required: false
default: app
build-args:
description: Docker build args
required: false
build-secrets:
description: Docker build secrets
required: false
github-token:
description: GitHub token to reduce the risk of rate limits when downloading the requested SetOps CLI
required: false
outputs:
image-digest:
value: ${{ steps.build_app.outputs.digest }}
description: The digest of the image that can was pushed
stages-json:
value: ${{ steps.prepare-stages-variables.outputs.stages-json }}
description: The given stages in stages format, so that they can be used as a matrix workflow input
runs:
using: "composite"
steps:
- name: "Detect SetOps target tag_names"
id: build_tag_names
run: |
declare -a tag_names
for stage in ${{ inputs.setops-stages }}; do
for app in ${{ inputs.setops-apps }}; do
tag_names+=("${{ inputs.setops-api-domain }}/${{ inputs.setops-organization }}/${{ inputs.setops-project }}/$stage/$app:${{ inputs.image-tag }}")
done
done
# https://stackoverflow.com/a/2317171
concatenated_tag_names=$(printf ",%s" "${tag_names[@]}")
concatenated_tag_names=${concatenated_tag_names:1}
echo "concatenated_tag_names=$concatenated_tag_names" >> $GITHUB_OUTPUT
shell: bash
# https://github.com/actions/cache#creating-a-cache-key
# http://man7.org/linux/man-pages/man1/date.1.html
- name: Get Date
id: get_date
run: |
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash
- name: "Set up Docker Buildx"
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ steps.get_date.outputs.date }}-${{ inputs.build-cache-key-prefix }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-${{ steps.get_date.outputs.date }}-${{ inputs.build-cache-key-prefix }}-
- name: Install SetOps CLI
uses: setopsco/github-actions/setup@v4
with:
setops_api_url: https://${{ inputs.setops-api-domain }}
setops_organization: ${{ inputs.setops-organization }}
setops_username: ${{ inputs.setops-username }}
setops_password: ${{ inputs.setops-password }}
setops_version: ${{ inputs.setops-version }}
github_token: ${{ inputs.github-token }}
- name: Build and push app
id: build_app
uses: docker/build-push-action@v6
with:
context: ${{ inputs.build-context }}
push: true
tags: ${{ steps.build_tag_names.outputs.concatenated_tag_names }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
build-args: ${{ inputs.build-args }}
secrets: ${{ inputs.build-secrets }}
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
shell: bash
# We need the stages variable in a json format for the next job, so
# we convert it with jq to JSON
- name: "Prepare setops-stages variable"
id: prepare-stages-variables
run: |
stages_json=$(echo ${{ inputs.setops-stages }} | jq -Rc 'split(" ")')
echo "stages-json=$stages_json" >> $GITHUB_OUTPUT
shell: bash