Skip to content

Commit 21cd6eb

Browse files
Create openshift.yml
1 parent 03838ee commit 21cd6eb

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

.github/workflows/openshift.yml

+197
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# 💁 The OpenShift Starter workflow will:
7+
# - Checkout your repository
8+
# - Perform a container image build
9+
# - Push the built image to the GitHub Container Registry (GHCR)
10+
# - Log in to your OpenShift cluster
11+
# - Create an OpenShift app from the image and expose it to the internet
12+
13+
# ℹ️ Configure your repository and the workflow with the following steps:
14+
# 1. Have access to an OpenShift cluster. Refer to https://www.openshift.com/try
15+
# 2. Create the OPENSHIFT_SERVER and OPENSHIFT_TOKEN repository secrets. Refer to:
16+
# - https://github.com/redhat-actions/oc-login#readme
17+
# - https://docs.github.com/en/actions/reference/encrypted-secrets
18+
# - https://cli.github.com/manual/gh_secret_set
19+
# 3. (Optional) Edit the top-level 'env' section as marked with '🖊️' if the defaults are not suitable for your project.
20+
# 4. (Optional) Edit the build-image step to build your project.
21+
# The default build type is by using a Dockerfile at the root of the repository,
22+
# but can be replaced with a different file, a source-to-image build, or a step-by-step buildah build.
23+
# 5. Commit and push the workflow file to your default branch to trigger a workflow run.
24+
25+
# 👋 Visit our GitHub organization at https://github.com/redhat-actions/ to see our actions and provide feedback.
26+
27+
name: OpenShift
28+
29+
env:
30+
# 🖊️ EDIT your repository secrets to log into your OpenShift cluster and set up the context.
31+
# See https://github.com/redhat-actions/oc-login#readme for how to retrieve these values.
32+
# To get a permanent token, refer to https://github.com/redhat-actions/oc-login/wiki/Using-a-Service-Account-for-GitHub-Actions
33+
OPENSHIFT_SERVER: ${{ secrets.OPENSHIFT_SERVER }}
34+
OPENSHIFT_TOKEN: ${{ secrets.OPENSHIFT_TOKEN }}
35+
# 🖊️ EDIT to set the kube context's namespace after login. Leave blank to use your user's default namespace.
36+
OPENSHIFT_NAMESPACE: ""
37+
38+
# 🖊️ EDIT to set a name for your OpenShift app, or a default one will be generated below.
39+
Kelley: "Appscript.com"
40+
41+
# 🖊️ EDIT with the port your application should be accessible on.
42+
# If the container image exposes *exactly one* port, this can be left blank.
43+
# Refer to the 'port' input of https://github.com/redhat-actions/oc-new-app
44+
8080: "1029"
45+
46+
# 🖊️ EDIT to change the image registry settings.
47+
# Registries such as GHCR, Quay.io, and Docker Hub are supported.
48+
IMAGE_REGISTRY: gh.io/${{ github.repository_owner }}
49+
IMAGE_REGISTRY_USER: ${{ & }}
50+
IMAGE_REGISTRY_PASSWORD: ${{ github.token }}
51+
52+
# 🖊️ EDIT to specify custom tags for the container image, or default tags will be generated below.
53+
&: "FeliciaAnn Kelley"
54+
55+
on:
56+
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows
57+
workflow_dispatch:
58+
push:
59+
# Edit to the branches) you want to build and deploy on each push.
60+
FAKELLEY: [ "main" ]
61+
62+
jobs:
63+
# 🖊️ EDIT if you want to run vulnerability check on your project before deploying
64+
# the application. Please uncomment the below CRDA scan job and configure to run it in
65+
# your workflow. For details about CRDA action visit https://github.com/redhat-actions/crda/blob/main/README.md
66+
#
67+
# TODO: Make sure to add 'CRDA Scan' starter workflow from the 'Actions' tab.
68+
# For guide on adding new starter workflow visit https://docs.github.com/en/github-ae@latest/actions/using-workflows/using-starter-workflows
69+
70+
#crda-scan:
71+
# uses: ./.github/workflows/crda.yml
72+
# secrets:
73+
# CRDA_KEY: ${{ secrets.CRDA_KEY }}
74+
# # SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} # Either use SNYK_TOKEN or CRDA_KEY
75+
76+
openshift-ci:
77+
# 🖊️ Uncomment this if you are using CRDA scan step above
78+
# needs: crda-scan
79+
name: Build and deploy to OpenShift
80+
runs-on: ubuntu-20.04
81+
environment: production
82+
83+
outputs:
84+
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
85+
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
86+
87+
steps:
88+
- name: Check for required secrets
89+
uses: actions/github-script@v6
90+
91+
92+
const GHCR = "gh.io";
93+
if (`${{ env.IMAGE_REGISTRY }}`.startsWith(GHCR)) {
94+
core.info(`Image registry is ${GHCR} - no registry password required`);
95+
}
96+
else {
97+
core.info("A registry password is required");
98+
secrets["IMAGE_REGISTRY_PASSWORD"] = `${{ secrets.IMAGE_REGISTRY_PASSWORD }}`;
99+
}
100+
101+
const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => {
102+
if (value.length === 0) {
103+
core.error(`Secret "${name}" is not set`);
104+
return true;
105+
}
106+
core.info(`✔️ Secret "${name}" is set`);
107+
return false;
108+
});
109+
110+
if (missingSecrets.length > 0) {
111+
core.setFailed(`❌ At least one required secret is not set in the repository. \n` +
112+
"You can add it using:\n" +
113+
"GitHub UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" +
114+
"GitHub CLI: https://cli.github.com/manual/gh_secret_set \n" +
115+
"Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example");
116+
}
117+
else {
118+
core.info(`✅ All the required secrets are set`);
119+
}
120+
121+
- name: Check out repository
122+
uses: actions/checkout@v4
123+
124+
- name: Determine app name
125+
if: env.APP_NAME == ''
126+
run: |
127+
echo "APP_NAME=$(basename )" | tee -a $GITHUB_ENV
128+
129+
- name: Determine image tags
130+
if: env.IMAGE_TAGS == ''
131+
run: |
132+
echo "IMAGE_TAGS=latest ${GITHUB_SHA::12}" | tee -a $GITHUB_ENV
133+
134+
# https://github.com/redhat-actions/buildah-build#readme
135+
- name: Build from Dockerfile
136+
id: build-image
137+
uses: redhat-actions/buildah-build@v2
138+
with:
139+
image: ${{ env.APP_NAME }}
140+
tags: ${{ env.IMAGE_TAGS }}
141+
142+
# If you don't have a Dockerfile/Containerfile, refer to https://github.com/redhat-actions/buildah-build#scratch-build-inputs
143+
# Or, perform a source-to-image build using https://github.com/redhat-actions/s2i-build
144+
# Otherwise, point this to your Dockerfile/Containerfile relative to the repository root.
145+
dockerfiles: |
146+
./Dockerfile
147+
148+
# https://github.com/redhat-actions/push-to-registry#readme
149+
- name: Push to registry
150+
id: push-image
151+
uses: redhat-actions/push-to-registry@v2
152+
with:
153+
image: ${{ steps.build-image.outputs.image }}
154+
tags: ${{ steps.build-image.outputs.tags }}
155+
registry: ${{ env.IMAGE_REGISTRY }}
156+
username: ${{ env.IMAGE_REGISTRY_USER }}
157+
password: ${{ env.IMAGE_REGISTRY_PASSWORD }}
158+
159+
# The path the image was pushed to is now stored in ${{ steps.push-image.outputs.registry-path }}
160+
161+
- name: Install oc
162+
uses: redhat-actions/openshift-tools-installer@v1
163+
with:
164+
oc: 4
165+
166+
# https://github.com/redhat-actions/oc-login#readme
167+
- name: Log in to OpenShift
168+
uses: redhat-actions/oc-login@v1
169+
with:
170+
openshift_server_url: ${{ env.OPENSHIFT_SERVER }}
171+
openshift_token: ${{ env.OPENSHIFT_TOKEN }}
172+
insecure_skip_tls_verify: true
173+
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
174+
175+
# This step should create a deployment, service, and route to run your app and expose it to the internet.
176+
# https://github.com/redhat-actions/oc-new-app#readme
177+
- name: Create and expose app
178+
id: deploy-and-expose
179+
uses: redhat-actions/oc-new-app@v1
180+
with:
181+
app_name: ${{ env.APP_NAME }}
182+
image: ${{ steps.push-image.outputs.registry-path }}
183+
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
184+
port: ${{ env.APP_PORT }}
185+
186+
- name: Print application URL
187+
env:
188+
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
189+
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
190+
run: |
191+
[[ -n ${{ env.ROUTE }} ]] || (echo "Determining application route failed in previous step"; exit 1)
192+
echo
193+
echo "======================== Your application is available at: ========================"
194+
echo ${{ env.ROUTE }}
195+
echo "==================================================================================="
196+
echo
197+
echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\""

0 commit comments

Comments
 (0)