Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1115 manual demo deplay #1155

Merged
merged 6 commits into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 38 additions & 81 deletions .github/workflows/demo-deploy-action.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
name: 'Demo-Deploy'

on:
# pull_request:
# types:
# - closed
# branches: [ main ]
workflow_dispatch:

jobs:
update-version:
if: github.event.pull_request.merged == true
get-e2e-files:
runs-on: ubuntu-24.04
outputs:
file_list: ${{ steps.generate-file-list.outputs.file_list }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Generate file list
id: generate-file-list
run: |
FILES=$(ls frontend/cypress/e2e | jq -R . | jq -s . | jq -c)
echo $FILES
echo "file_list=$FILES" >> $GITHUB_OUTPUT

read-version:
runs-on: ubuntu-24.04
outputs:
okr-docker-image: ${{ vars.NEW_VALUE_URL }}:${{ steps.store-version.outputs.version}}-DEMO
steps:
- uses: actions/checkout@v4
with:
token: ${{secrets.VERSION_TOKEN}}

- name: Generate and Set New Version
run: mvn build-helper:parse-version versions:set -DnewVersion=\${parsedVersion.majorVersion}.\${parsedVersion.minorVersion}.\${parsedVersion.nextIncrementalVersion} -DgenerateBackupPoms=false

- name: Extract Maven project version
run: echo "version=$(mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec)" >> $GITHUB_OUTPUT
id: store-version

- name: Set New Snapshot Version
run: mvn build-helper:parse-version versions:set -DnewVersion=${{ steps.store-version.outputs.version}}-SNAPSHOT -DgenerateBackupPoms=false

- name: Commit and Push Changes
shell: bash
env:
COMMITPREFIX: '[VU]'
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add . || {
echo "No files were changed, so we did not commit anything"
exit 1
}
git commit -m "$COMMITPREFIX Automated version update" || {
echo "No changes to commit, skipping push"
exit 0
}
git push -f origin main

build-docker-image:
needs: update-version
needs: read-version
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
Expand All @@ -59,7 +45,7 @@ jobs:
- name: Set up node 18
uses: actions/setup-node@v4
with:
node-version: 18.17.1
node-version: ${{vars.NODE_VERSION}}

- name: Install Dependencies
run: cd ./frontend && npm ci
Expand All @@ -78,7 +64,7 @@ jobs:
with:
context: .
file: docker/Dockerfile
tags: ${{ needs.update-version.outputs.okr-docker-image}}
tags: ${{ needs.read-version.outputs.okr-docker-image}}
load: true
push: false
outputs: type=docker,dest=/tmp/okr-docker-image.tar
Expand All @@ -89,12 +75,13 @@ jobs:
name: okr-image
path: /tmp/okr-docker-image.tar

- name: print imagetags
run: echo ${{ needs.update-version.outputs.okr-docker-image}}

e2e-docker:
runs-on: ubuntu-24.04
needs: [build-docker-image,update-version]
needs: [build-docker-image, read-version, get-e2e-files]
strategy:
fail-fast: false
matrix:
file: ${{ fromJSON(needs.get-e2e-files.outputs.file_list) }}
steps:
- uses: actions/checkout@v4

Expand All @@ -107,59 +94,37 @@ jobs:
- name: Load image
run: docker load --input /tmp/okr-docker-image.tar

- name: show images
run: docker image ls -a
- name: Run keyloak server
run: cd docker && docker compose up -d keycloak-pitc

- name: Run docker image
- name: run Springboot okr application
run: |
docker run --network=host \
-p 8080:8080 \
-e SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_ISSUER-URI=http://localhost:8544/realms/pitc \
-e SPRING_SECURITY_OAUTH2_RESOURCESERVER_JWT_JWK-SET-URI=http://localhost:8544/realms/pitc/protocol/openid-connect/certs \
-e SPRING_SECURITY_OAUTH2_RESOURCESERVER_OPAQUETOKEN_CLIENT-ID=pitc_okr_staging \
-e SPRING_PROFILES_ACTIVE-ID=integration-test \
-e SPRING_DATASOURCE_URL="jdbc:h2:mem:db;DB_CLOSE_DELAY=-1" \
-e SPRING_DATASOURCE_USERNAME=user \
-e SPRING_DATASOURCE_PASSWORD=sa \
-e SPRING_FLYWAY_LOCATIONS="classpath:db/h2-db/database-h2-schema,classpath:db/h2-db/data-test-h2" \
${{ needs.update-version.outputs.okr-docker-image}} &

- name: run keycloak docker
run: |
docker run \
-e KEYCLOAK_ADMIN=admin \
-e KEYCLOAK_ADMIN_PASSWORD=keycloak \
-v ./docker/config/realm-export.json:/opt/keycloak/data/import/realm.json \
-p 8544:8080 \
quay.io/keycloak/keycloak:23.0.1 \
start-dev --import-realm &

- uses: abhi1693/[email protected]
with:
browser: chrome
version: latest
-e SPRING_PROFILES_ACTIVE=integration-test \
${{ needs.read-version.outputs.okr-docker-image}} &

- name: Cypress run e2e tests
uses: cypress-io/github-action@v6
with:
build: npm i -D cypress
working-directory: frontend
install: false
wait-on: 'http://pitc.okr.localhost:8080/config, http://pitc.okr.localhost:4200, http://localhost:8544'
wait-on: 'http://pitc.okr.localhost:8080/config, http://localhost:8544'
wait-on-timeout: 120
browser: chrome
headed: true
working-directory: frontend
headed: false
config: baseUrl=http://pitc.okr.localhost:8080
spec: cypress/e2e/${{ matrix.file }}

- uses: actions/upload-artifact@v4
if: always()
with:
name: cypress-screenshots
name: cypress-screenshots for ${{ matrix.file }}
path: frontend/cypress/screenshots

upload-to-quay:
runs-on: ubuntu-latest
needs: [e2e-docker, update-version]
needs: [e2e-docker, read-version]
steps:
- uses: actions/checkout@v4

Expand All @@ -183,7 +148,7 @@ jobs:
password: ${{ secrets.QUAY_TOKEN }}

- name: Push
run: docker push ${{ needs.update-version.outputs.okr-docker-image}}
run: docker push ${{ needs.read-version.outputs.okr-docker-image}}

- name: Install yq
shell: bash
Expand All @@ -200,7 +165,7 @@ jobs:
COMMITPREFIX: '[CTS]'
run: |
curl -s --header "PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}?ref=${{vars.TARGET_GITLAB_REFERENCE}}" -H "Accept: application/json" -H "Content-Type: application/json" | jq -r '.content' | base64 --decode > response.yaml
yq -i "${{vars.YAML_PATH}} = \"${{needs.update-version.outputs.okr-docker-image}}\"" response.yaml
yq -i "${{vars.YAML_PATH}} = \"${{needs.read-version.outputs.okr-docker-image}}\"" response.yaml
UPDATED_CONTENT=$(cat response.yaml)
curl --request PUT --header 'PRIVATE-TOKEN: ${{secrets.GITLAB_ACCESS_TOKEN}}' -F "branch=${{vars.TARGET_GITLAB_REFERENCE}}" -F "[email protected]" -F "author_name=GitLab Actions" -F "content=${UPDATED_CONTENT}" -F "commit_message=$COMMITPREFIX Automated changes to ${{vars.FILEPATH_COMMIT}}" "${{vars.TARGET_GITLAB_REPOSITORY}}/files/${{vars.GITLAB_FILEPATH}}"

Expand Down Expand Up @@ -238,11 +203,3 @@ jobs:
--form "projectName=${PROJECT_NAME:-$GITHUB_REPOSITORY}" \
--form "projectVersion=latest" \
--form "[email protected]"

clean-up:
needs: [generate-and-push-sbom]
runs-on: ubuntu-latest

steps:
- name: remove dockers
run: docker ps -aq | xargs -r docker rm -f
Loading