This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
189 lines (157 loc) · 7.08 KB
/
tnf-image.yaml
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
name: 'Publish the `test-network-function` image (latest release only)'
on:
# Run the workflow when a new release gets published
release:
types: [published]
# Run the workflow every day at 5 am UTC (1 am EST, 7am CET)
# This is useful for keeping the image up-to-date with security
# patches provided in the UBI.
# Disclaimer: There is no guarantee that scheduled workflows will
# run at the predefined time, if at all. The delay is usually
# around 10-30 minutes.
schedule:
- cron: '0 5 * * *'
workflow_dispatch:
defaults:
run:
shell: bash
env:
REGISTRY: quay.io
REGISTRY_LOCAL: localhost
IMAGE_NAME: testnetworkfunction/test-network-function
IMAGE_TAG: latest
TNF_CONTAINER_CLIENT: docker
TNF_NON_INTRUSIVE_ONLY: false
TNF_MINIKUBE_ONLY: true
TNF_DISABLE_CONFIG_AUTODISCOVER: false
TNF_CONFIG_DIR: /tmp/tnf/config
TNF_OUTPUT_DIR: /tmp/tnf/output
TNF_SRC_URL: 'https://github.com/${{ github.repository }}'
PARTNER_REPO: test-network-function/cnf-certification-test-partner
PARTNER_SRC_URL: 'https://github.com/${PARTNER_REPO}'
TESTING_CMD_PARAMS: '-n host -i ${REGISTRY_LOCAL}/${IMAGE_NAME}:${IMAGE_TAG} -t ${TNF_CONFIG_DIR} -o ${TNF_OUTPUT_DIR}'
LATEST_BRANCH_VERSION: 3.3.x
jobs:
test-and-push-tnf-image:
name: 'Test and push the `test-network-function` image'
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
branch: [3.1.x, 3.2.x, 3.3.x]
env:
SHELL: /bin/bash
KUBECONFIG: '/home/runner/.kube/config'
CURRENT_VERSION_GENERIC_BRANCH: ${{ matrix.branch }}
TNF_VERSION: ""
PARTNER_VERSION: ""
steps:
- name: Checkout generic working branch of the current version
uses: actions/checkout@v2
with:
ref: ${{ env.CURRENT_VERSION_GENERIC_BRANCH }}
fetch-depth: '0'
- name: Get the latest TNF version from GIT
run: |
GIT_RELEASE=$(git tag --points-at HEAD | head -n 1)
GIT_PREVIOUS_RELEASE=$(git tag --no-contains HEAD --sort=v:refname | tail -n 1)
GIT_LATEST_RELEASE=$GIT_RELEASE
if [ -z "$GIT_RELEASE" ]; then
GIT_LATEST_RELEASE=$GIT_PREVIOUS_RELEASE
fi
echo "::set-output name=version_number::$GIT_LATEST_RELEASE"
id: set_tnf_version
- name: Print the latest TNF version from GIT
run: |
echo Version tag: ${{ steps.set_tnf_version.outputs.version_number }}
- name: Get contents of the version.json file
run: echo "::set-output name=json::$(cat version.json | tr -d '[:space:]')"
id: get_version_json_file
- name: Get the partner version number from file
run: |
echo Partner version tag: $VERSION_FROM_FILE_PARTNER
echo "::set-output name=partner_version_number::$VERSION_FROM_FILE_PARTNER"
id: set_partner_version
env:
VERSION_FROM_FILE_PARTNER: ${{ fromJSON(steps.get_version_json_file.outputs.json).partner_tag }}
- name: Update env variables
run: |
echo "TNF_VERSION=${{ steps.set_tnf_version.outputs.version_number }}" >> $GITHUB_ENV
echo "PARTNER_VERSION=${{ steps.set_partner_version.outputs.partner_version_number }}" >> $GITHUB_ENV
- name: Ensure $TNF_VERSION and $IMAGE_TAG are set
run: '[[ -n "$TNF_VERSION" ]] && [[ -n "$IMAGE_TAG" ]] && [[ -n "$PARTNER_VERSION" ]]'
- name: Check whether the version tag exists on remote
run: git ls-remote --exit-code $TNF_SRC_URL refs/tags/$TNF_VERSION
- name: (if tag is missing) Display debug message
if: ${{ failure() }}
run: echo "Tag '$TNF_VERSION' does not exist on remote $TNF_SRC_URL"
- name: Check whether the version tag exists on remote
run: git ls-remote --exit-code ${{ env.PARTNER_SRC_URL }} refs/tags/$PARTNER_VERSION
- name: (if partner_tag is missing) Display debug message
if: ${{ failure() }}
run: echo "Tag '$PARTNER_VERSION' does not exist on remote $PARTNER_SRC_URL"
- name: Checkout the version tag
uses: actions/checkout@v2
with:
ref: ${{ env.TNF_VERSION }}
- name: Build the `test-network-function` image
run: |
docker build --no-cache \
-t ${REGISTRY_LOCAL}/${IMAGE_NAME}:${IMAGE_TAG} \
-t ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG} \
-t ${REGISTRY}/${IMAGE_NAME}:${TNF_VERSION} \
--build-arg TNF_VERSION=${TNF_VERSION} \
--build-arg TNF_SRC_URL=${TNF_SRC_URL} .
# Create a minikube cluster for testing.
- name: Check out `cnf-certification-test-partner`
uses: actions/checkout@v2
with:
repository: test-network-function/cnf-certification-test-partner
path: cnf-certification-test-partner
ref: ${{ env.PARTNER_VERSION }}
# Only one of the following 2 steps will work depending on the repo version
# For versions > 3.3.0
- name: Check for start-k8s-cluster existence
id: check_start_k8s_cluster
uses: andstor/file-existence-action@v1
with:
files: "./cnf-certification-test-partner/.github/actions/start-k8s-cluster"
- name: Start the k8s cluster for `local-test-infra`
if: steps.check_start_k8s_cluster.outputs.files_exists == 'true'
uses: ./cnf-certification-test-partner/.github/actions/start-k8s-cluster
# For version <= 3.3.0
- name: Check for start-minikube existence
id: check_start_minikube
uses: andstor/file-existence-action@v1
with:
files: "./cnf-certification-test-partner/.github/actions/start-minikube"
- name: Start the minikube cluster for `local-test-infra`
if: steps.check_start_minikube.outputs.files_exists == 'true'
uses: ./cnf-certification-test-partner/.github/actions/start-minikube
- name: Create `local-test-infra` OpenShift resources
uses: ./cnf-certification-test-partner/.github/actions/create-local-test-infra-resources
with:
working_directory: cnf-certification-test-partner
# Perform tests.
- name: Create required TNF config files and directories
run: |
mkdir -p $TNF_CONFIG_DIR $TNF_OUTPUT_DIR
cp test-network-function/*.yml $TNF_CONFIG_DIR
shell: bash
- name: 'Test: Run without any TS, just get diagnostic information'
run: ./run-tnf-container.sh ${{ env.TESTING_CMD_PARAMS }} -f diagnostic
# Push the new TNF image to Quay.io.
- name: Authenticate against Quay.io
uses: docker/login-action@v1
with:
registry: ${{ env.REGISTRY }}
# Use a Robot Account to authenticate against Quay.io
# https://docs.quay.io/glossary/robot-accounts.html
username: ${{ secrets.QUAY_ROBOT_USERNAME }}
password: ${{ secrets.QUAY_ROBOT_TOKEN }}
- name: Push the newly built image to Quay.io
run: |
docker push ${REGISTRY}/${IMAGE_NAME}:${TNF_VERSION}
if [ "$CURRENT_VERSION_GENERIC_BRANCH" == "$LATEST_BRANCH_VERSION" ]; then
docker push ${REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}
fi