-
Notifications
You must be signed in to change notification settings - Fork 19
174 lines (151 loc) · 5.7 KB
/
example.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
name: Create Knative service
on:
push:
workflow_dispatch:
schedule:
- cron: '0 0 * * *' # every day at midnight
env:
IMAGE_REGISTRY: quay.io
IMAGE_NAME: getting-started-knative
IMAGE_NAMESPACE: redhat-github-actions
BASE_IMAGE: registry.access.redhat.com/ubi8/openjdk-11
PROJECT_DIR: getting-started-knative
TARGET_DIR: target/
MVN_REPO_DIR: ~/.m2/repository
TEST_NAMESPACE: crt-redhat-github-actions-bot-dev
jobs:
checkout-and-build:
name: Build
runs-on: ubuntu-20.04
steps:
# Checkout project repository
- name: Checkout example repository
uses: actions/checkout@v2
with:
repository: redhat-actions/quarkus-quickstarts
# If none of these files has changed, we assume that the contents of
# .m2/repository can be fetched from the cache.
- name: Hash Maven files
working-directory: ${{ env.PROJECT_DIR }}
run: |
echo "MVN_HASH=${{ hashFiles('**/pom.xml', '.mvn/**/*', 'mvnw*') }}" >> $GITHUB_ENV
# Download the m2 repository from the cache to speed up the build.
- name: Check for Maven cache
id: check_mvn_cache
uses: actions/cache@v2
with:
path: ${{ env.MVN_REPO_DIR }}
key: ${{ env.MVN_HASH }}
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Maven Build
id: build_app
working-directory: ${{ env.PROJECT_DIR }}
run: mvn -B -DskipTests clean package --file pom.xml
# If there was no cache hit above, store the output into the cache now.
- name: Save Maven repo into cache
if: ${{ steps.check_mvn_cache.outputs.cache-hit }} != 'true'
uses: actions/cache@v2
with:
path: ${{ env.MVN_REPO_DIR }}
key: ${{ env.MVN_HASH }}
# Store the output jar into the env for reuse below.
- name: Get jar filename
run: |
export JAR_NAME="$(basename $(ls ${{ env.PROJECT_DIR }}/target/*.jar))"
echo "${{ env.PROJECT_DIR }} App jar is $JAR_NAME"
echo "::set-output name=jarname::$JAR_NAME"
echo "JAR_NAME=$JAR_NAME" >> $GITHUB_ENV
# Upload the source code for future jobs to use.
- name: Upload working directory
uses: actions/upload-artifact@v2
with:
name: ${{ env.PROJECT_DIR }}
path: ./
if-no-files-found: error
build-and-deploy-images:
name: Deploy Knative Service
runs-on: ubuntu-20.04
needs: [ checkout-and-build ]
steps:
# Checkout Knative service deploy action github repository
- name: Checkout Knative service deploy action
uses: actions/checkout@v2
with:
path: "kn-service-manager"
- name: Download working directory
uses: actions/download-artifact@v2
with:
name: ${{ env.PROJECT_DIR }}
- name: Get Commit Metadata
uses: redhat-actions/common/commit-data@v1
id: commit_metadata
with:
working_directory: "kn-service-manager"
- name: Determine image tag
shell: bash
run: |
export IMG_TAGS=latest
export GIT_TAG="${{ steps.commit_metadata.outputs.tag }}"
if [[ -n "$GIT_TAG" ]]; then
IMG_TAGS=$GIT_TAG
else
IMG_TAGS="${{ steps.commit_metadata.outputs.short_sha }}"
fi
IMG_TAGS=$(echo $IMG_TAGS | tr -d -c '[:alnum:]_-' | tr '[:upper:]' '[:lower:]')
echo "IMG_TAGS=$IMG_TAGS" | tee -a $GITHUB_ENV
# Build container image using Buildah Action
- name: Build Image
id: buildah_build
uses: redhat-actions/buildah-build@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ env.IMG_TAGS }}
base-image: ${{ env.BASE_IMAGE }}
context: ${{ env.PROJECT_DIR }}
dockerfiles: |
./${{ env.PROJECT_DIR }}/src/main/docker/Dockerfile.jvm
- name: Push To Quay
id: push_tag_to_quay
uses: redhat-actions/push-to-registry@v2
with:
image: ${{ env.IMAGE_NAME }}
tags: ${{ steps.buildah_build.outputs.tags }}
registry: ${{ env.IMAGE_REGISTRY }}/${{ env.IMAGE_NAMESPACE }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Login into OpenShift Cluster
uses: redhat-actions/oc-login@v1
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.TEST_NAMESPACE }}
- name: Deploy Knative Service
id: kn_service_deploy
uses: ./kn-service-manager/
with:
service_name: "test-service"
container_image: "${{ steps.push_tag_to_quay.outputs.registry-path }}"
- name: Show Kn Service URL
run: echo ${{ steps.kn_service_deploy.outputs.service_url }}
# Perform a (very) basic integration test.
# This step is retried since the time to pull the image and start the pod can vary.
- name: Test project is running
uses: nick-invision/retry@v2.2.0
with:
timeout_seconds: 3
retry_wait_seconds: 10
max_attempts: 10
warning_on_retry: false
# Just check that the root endpoint returns a success status (-f flag).
command: curl -sSfLi ${{ steps.kn_service_deploy.outputs.service_url }}
# Clean up the resources we deployed, even if there was an error above.
- name: Delete deployed knative service
uses: ./kn-service-manager/
if: always()
with:
service_name: "test-service"
command: delete