-
Notifications
You must be signed in to change notification settings - Fork 98
246 lines (218 loc) · 8.51 KB
/
ee.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
name: Ansible EE Image
on:
workflow_call:
inputs:
release:
description: Prepare EE for a release
type: boolean
default: false
release_tag: # tag starting with 'v' like v1.2.3
description: Git tag for release to prepare EE
type: string
required: false
workflow_dispatch:
inputs:
release:
description: EE for a release or development
type: boolean
default: false
env:
NAMESPACE: paloaltonetworks
COLLECTION_NAME: panos
jobs:
build_ee:
name: Ansible EE
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
# if event == push (same event from workflow_call) and inputs.release == true
# release_tag must be given as input
# checkout tag and prepare EE on tag
# elif event == workflow_dispatch and inputs.release == true
# workflow must be run on a tag
# checkout tag and prepare EE on tag
# else - could be workflow_call or workflow_dispatch with release false
# normal checkout - it will checkout whatever the workflow is run on
# prepare EE on branch
- name: check and findout the tag
id: tag
# outputs tag name as v1.2.3 and version as 1.2.3
run: |
if [[ "${{ github.event_name }}" == "push" &&
"${{ inputs.release }}" == "true" ]]; then
if [[ "${{ inputs.release_tag }}" != "v"* ]]; then
echo "release_tag (${{ inputs.release_tag }}) must be provided when workflow_call called with release."
exit 1
fi
TAG_VERSION=$(echo "${{inputs.release_tag}}" | sed 's#v##')
echo "name=${{inputs.release_tag}}" >> $GITHUB_OUTPUT
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "Ansible EE will be prepared for release ${{ inputs.release_tag }}"
elif [[ "${{ github.event_name }}" == "workflow_dispatch" &&
"${{ inputs.release }}" == "true" ]]; then
if [[ "${GITHUB_REF}" != "refs/tags/v"* ]]; then
echo "workflow_dispatch must be run on a release tag when release is selected - run on ${GITHUB_REF}"
exit 1
fi
TAG_NAME=$(echo "${GITHUB_REF}" | sed 's#refs/tags/##')
TAG_VERSION=$(echo "${TAG_NAME}" | sed 's#v##')
echo "name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "version=$TAG_VERSION" >> $GITHUB_OUTPUT
echo "Ansible EE will be prepared for release $TAG_NAME"
else
echo "Ansible EE will be prepared for branch ${GITHUB_REF#refs/heads/}"
fi
env:
GITHUB_REF: ${{ github.ref }}
# checkout tag for releae otherwise checkout branch
- name: check out code
uses: actions/checkout@v4
with:
# if tag is empty; github.ref else tag.outputs.name
ref: ${{ steps.tag.outputs.name == '' && github.ref || steps.tag.outputs.name }}
- name: discover Python version
id: pyversion
uses: PaloAltoNetworks/pan-os-upgrade-assurance/.github/actions/discover_python_version@v0.3.1
- name: install Python
uses: actions/setup-python@v4
with:
python-version: ${{ steps.pyversion.outputs.pyversion }}
cache: pip
- name: install Poetry
uses: Gr1N/setup-poetry@v8
- name: prep Poetry venv
run: |
poetry env use ${{ steps.pyversion.outputs.pyversion }}
poetry lock
poetry install --with ansible-ee --without dev --no-root
- name: set up Docker Buildx
uses: docker/setup-buildx-action@v3
# produce docker tags for semver if on a tag, otherwise take ref branch name
# latest tag is only produced for semver operating on a tag
- name: determine docker tags and labels
id: meta
uses: docker/metadata-action@v5
with:
context: git # git - this ensures to reference the current git context instead of workflow context (context info ref/sha)
images: ghcr.io/paloaltonetworks/pan-os-ansible
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
type=semver,pattern=v{{major}}
type=ref,event=branch
type=ref,event=tag
# take pan-os-ansible from galaxy for a release, but local build for develop
# ref - https://github.com/ansible-collections/community.dns/blob/main/.github/workflows/ee.yml#L96-L98
- name: Build collection from development branch
run: |
ansible-galaxy collection build
if: ${{ inputs.release == false }}
- name: create base EE file
run: |
cat > execution-environment.yml <<EOF
---
version: 3
images:
base_image:
name: quay.io/centos/centos:stream9
dependencies:
python_interpreter:
package_system: python3.9
python_path: /usr/bin/python3.9
ansible_core:
package_pip: ansible-core>=2.15.0rc2,<2.16
ansible_runner:
package_pip: ansible-runner
system: |
git-core [platform:rpm]
python3.9-devel [platform:rpm compile]
libcurl-devel [platform:rpm compile]
sshpass [platform:rpm]
rsync [platform:rpm]
epel-release [platform:rpm]
unzip [platform:rpm]
galaxy: requirements.yml
python: requirements-ee.txt
additional_build_steps:
append_base:
- RUN \$PYCMD -m pip install -U pip
append_final:
# SymLink `python` -> `python3.9`
- RUN alternatives --install /usr/bin/python python /usr/bin/python3.9 39
EOF
- name: append build files to EE for development
run: |
COLLECTION_FILENAME="$(ls "${{ env.NAMESPACE }}-${{ env.COLLECTION_NAME }}"-*.tar.gz)"
# append to existing EE file
cat >> execution-environment.yml <<EOF
additional_build_files:
- src: ${COLLECTION_FILENAME}
dest: src
EOF
echo "::group::execution-environment.yml"
cat execution-environment.yml
echo "::endgroup::"
cat > requirements.yml <<EOF
---
collections:
- name: src/${COLLECTION_FILENAME}
type: file
- name: awx.awx
- community.general
EOF
echo "::group::requirements.yml"
cat requirements.yml
echo "::endgroup::"
if: ${{ inputs.release == false }}
- name: append build files to EE for release
run: |
echo "::group::execution-environment.yml"
cat execution-environment.yml
echo "::endgroup::"
# Collection Requirements
cat > requirements.yml <<EOF
---
collections:
- name: paloaltonetworks.panos
version: ${{steps.tag.outputs.version}}
- name: awx.awx
- community.general
EOF
echo "::group::requirements.yml"
cat requirements.yml
echo "::endgroup::"
if: inputs.release
# when you build a collection the requirements.txt file is already included in it
# this is for additional packages we want to include in the EE image
- name: create additional requirements.txt for EE
run: |
# Python Requirements
cat > requirements-ee.txt <<EOF
jmespath
EOF
echo "::group::requirements-ee.txt"
cat requirements-ee.txt
echo "::endgroup::"
- name: create execution env context
run: |
poetry run ansible-builder create -v 3 --output-filename Dockerfile
ls -l ./context/
cat ./context/Dockerfile
- name: login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: build and publish
uses: docker/build-push-action@v5
with:
context: "./context/"
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
provenance: ${{ inputs.release }} # disable for development to keep number of images low