Modify openshift workflow with v2 version of actions and add oc-new-app (#1)
* Modify openshift workflow with v2 version of actions and add oc-new-app Signed-off-by: divyansh42 <[email protected]>
This commit is contained in:
committed by
divyansh42
parent
ab8c670faf
commit
7c8569ab2b
+55
-29
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
# For a more sophisticated example, see https://github.com/redhat-actions/spring-petclinic/blob/main/.github/workflows/petclinic-sample.yaml
|
# For a more sophisticated example, see https://github.com/redhat-actions/spring-petclinic/blob/main/.github/workflows/petclinic-sample.yaml
|
||||||
# Also see our GitHub organization, https://github.com/redhat-actions/
|
# Also see our GitHub organization, https://github.com/redhat-actions/
|
||||||
|
# ▶️ See a video of how to set up this workflow at https://www.youtube.com/watch?v=6hgBO-1pKho
|
||||||
|
|
||||||
name: OpenShift
|
name: OpenShift
|
||||||
|
|
||||||
@@ -52,6 +53,7 @@ env:
|
|||||||
|
|
||||||
# If you wish to manually provide the APP_NAME and TAG, set them here, otherwise they will be auto-detected.
|
# If you wish to manually provide the APP_NAME and TAG, set them here, otherwise they will be auto-detected.
|
||||||
APP_NAME: ""
|
APP_NAME: ""
|
||||||
|
|
||||||
TAG: ""
|
TAG: ""
|
||||||
|
|
||||||
on:
|
on:
|
||||||
@@ -66,7 +68,42 @@ jobs:
|
|||||||
runs-on: ubuntu-20.04
|
runs-on: ubuntu-20.04
|
||||||
environment: production
|
environment: production
|
||||||
|
|
||||||
|
outputs:
|
||||||
|
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
|
||||||
|
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
- name: Check if secrets exists
|
||||||
|
uses: actions/github-script@v3
|
||||||
|
with:
|
||||||
|
script: |
|
||||||
|
const secrets = {
|
||||||
|
REGISTRY_PASSWORD: `${{ secrets.REGISTRY_PASSWORD }}`,
|
||||||
|
OPENSHIFT_SERVER: `${{ secrets.OPENSHIFT_SERVER }}`,
|
||||||
|
OPENSHIFT_TOKEN: `${{ secrets.OPENSHIFT_TOKEN }}`,
|
||||||
|
};
|
||||||
|
|
||||||
|
const missingSecrets = Object.entries(secrets).filter(([ name, value ]) => {
|
||||||
|
if (value.length === 0) {
|
||||||
|
core.warning(`Secret "${name}" is not set`);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
core.info(` ✔️ Secret "${name}" is set`);
|
||||||
|
return false;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
if (missingSecrets.length > 0) {
|
||||||
|
core.setFailed(`❌ At least one required secret is not set in the repository. \n` +
|
||||||
|
"You can add it using:\n" +
|
||||||
|
"Github UI: https://docs.github.com/en/actions/reference/encrypted-secrets#creating-encrypted-secrets-for-a-repository \n" +
|
||||||
|
"Github CLI: https://cli.github.com/manual/gh_secret_set \n" +
|
||||||
|
"Also, refer to https://github.com/redhat-actions/oc-login#getting-started-with-the-action-or-see-example");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`✅ All the required secrets are set`);
|
||||||
|
}
|
||||||
|
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Determine app name
|
- name: Determine app name
|
||||||
@@ -81,12 +118,13 @@ jobs:
|
|||||||
|
|
||||||
# https://github.com/redhat-actions/buildah-build#readme
|
# https://github.com/redhat-actions/buildah-build#readme
|
||||||
- name: Build from Dockerfile
|
- name: Build from Dockerfile
|
||||||
uses: redhat-actions/buildah-build@v1
|
id: image-build
|
||||||
|
uses: redhat-actions/buildah-build@v2
|
||||||
with:
|
with:
|
||||||
image: ${{ env.APP_NAME }}
|
image: ${{ env.APP_NAME }}
|
||||||
tag: ${{ env.TAG }}
|
tags: ${{ env.TAG }}
|
||||||
# If you don't have a dockerfile, see:
|
# If you don't have a dockerfile, see:
|
||||||
# https://github.com/redhat-actions/buildah-build#building-from-scratch
|
# https://github.com/redhat-actions/buildah-build#scratch-build-inputs
|
||||||
# Otherwise, point this to your Dockerfile relative to the repository root.
|
# Otherwise, point this to your Dockerfile relative to the repository root.
|
||||||
dockerfiles: |
|
dockerfiles: |
|
||||||
./Dockerfile
|
./Dockerfile
|
||||||
@@ -94,10 +132,10 @@ jobs:
|
|||||||
# https://github.com/redhat-actions/push-to-registry#readme
|
# https://github.com/redhat-actions/push-to-registry#readme
|
||||||
- name: Push to registry
|
- name: Push to registry
|
||||||
id: push-to-registry
|
id: push-to-registry
|
||||||
uses: redhat-actions/push-to-registry@v1
|
uses: redhat-actions/push-to-registry@v2
|
||||||
with:
|
with:
|
||||||
image: ${{ env.APP_NAME }}
|
image: ${{ steps.image-build.outputs.image }}
|
||||||
tag: ${{ env.TAG }}
|
tags: ${{ steps.image-build.outputs.tags }}
|
||||||
registry: ${{ env.REGISTRY }}
|
registry: ${{ env.REGISTRY }}
|
||||||
username: ${{ env.REGISTRY_USER }}
|
username: ${{ env.REGISTRY_USER }}
|
||||||
password: ${{ env.REGISTRY_PASSWORD }}
|
password: ${{ env.REGISTRY_PASSWORD }}
|
||||||
@@ -118,30 +156,15 @@ jobs:
|
|||||||
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
|
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
|
||||||
|
|
||||||
# This step should create a deployment, service, and route to run your app and expose it to the internet.
|
# This step should create a deployment, service, and route to run your app and expose it to the internet.
|
||||||
# Feel free to replace this with 'oc apply', 'helm install', or however you like to deploy your app.
|
# https://github.com/redhat-actions/oc-new-app#readme
|
||||||
- name: Create and expose app
|
- name: Create and expose app
|
||||||
run: |
|
id: deploy-and-expose
|
||||||
export IMAGE="${{ steps.push-to-registry.outputs.registry-path }}"
|
uses: redhat-actions/oc-new-app@v1
|
||||||
export PORT=${{ env.APP_PORT }}
|
with:
|
||||||
|
app_name: ${{ env.APP_NAME }}
|
||||||
export SELECTOR="app=${{ env.APP_NAME }}"
|
image: ${{ steps.push-to-registry.outputs.registry-path }}
|
||||||
echo "SELECTOR=$SELECTOR" >> $GITHUB_ENV
|
namespace: ${{ env.OPENSHIFT_NAMESPACE }}
|
||||||
|
port: ${{ env.APP_PORT }}
|
||||||
set -x
|
|
||||||
# Take down any old deployment
|
|
||||||
oc delete all --selector="$SELECTOR"
|
|
||||||
oc new-app --name $APP_NAME --docker-image="$IMAGE"
|
|
||||||
|
|
||||||
# Make sure the app port is exposed
|
|
||||||
oc patch svc $APP_NAME -p "{ \"spec\": { \"ports\": [{ \"name\": \"$PORT-tcp\", \"port\": $PORT }] } }"
|
|
||||||
oc expose service $APP_NAME --port=$PORT
|
|
||||||
|
|
||||||
oc get all --selector="$SELECTOR"
|
|
||||||
set +x
|
|
||||||
|
|
||||||
export ROUTE="$(oc get route $APP_NAME -o jsonpath='{.spec.host}')"
|
|
||||||
echo "$APP_NAME is exposed at $ROUTE"
|
|
||||||
echo "ROUTE=$ROUTE" >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: View application route
|
- name: View application route
|
||||||
run: |
|
run: |
|
||||||
@@ -151,3 +174,6 @@ jobs:
|
|||||||
echo "==================================================================================="
|
echo "==================================================================================="
|
||||||
echo
|
echo
|
||||||
echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\""
|
echo "Your app can be taken down with: \"oc delete all --selector='${{ env.SELECTOR }}'\""
|
||||||
|
env:
|
||||||
|
ROUTE: ${{ steps.deploy-and-expose.outputs.route }}
|
||||||
|
SELECTOR: ${{ steps.deploy-and-expose.outputs.selector }}
|
||||||
|
|||||||
Reference in New Issue
Block a user