From 7a5d5cf846f840add0416838c803e91b3d3cd0f8 Mon Sep 17 00:00:00 2001 From: dhruv Date: Thu, 22 Aug 2024 10:48:21 +0530 Subject: [PATCH 1/2] Added main and PR build worlflows along with test report generation/logging Signed-off-by: dhruv --- .github/workflows/build.yaml | 120 +++++++++++++++++++++++ .github/workflows/pr-build.yaml | 63 ++++++++++++ dockerfiles/dockerfile.simplatform | 11 +++ dockerfiles/dockerfile.simplatform-amd64 | 20 ++++ 4 files changed, 214 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .github/workflows/pr-build.yaml create mode 100644 dockerfiles/dockerfile.simplatform create mode 100644 dockerfiles/dockerfile.simplatform-amd64 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..4c2a5d7 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,120 @@ +name: Main Build + +on: + push: + branches: [main] + +env: + REGISTRY: ghcr.io + NAMESPACE: galasa-dev + +jobs: + build-simplatform: + name: Building Simplatform + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'semeru' + cache: maven + + - name: Print Githash + run: | + echo $GITHUB_SHA > ./simplatform.githash + + - name: Building galasa-simplatform-application using maven + run: | + set -o pipefail + mvn -f galasa-simplatform-application/pom.xml -X deploy \ + -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ + -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ + -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ + --batch-mode --errors --fail-at-end \ + --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simplatform-application-build.log + + - name: Upload galasa-simplatform-application Maven Build Log + if: always() + uses: actions/upload-artifact@v4 + with: + name: galasa-simplatform-application-build-log + path: galasa-simplatform-application-build.log + + - name: Building galasa-simbank-tests using maven + run: | + set -o pipefail + mvn -f galasa-simbank-tests/pom.xml -X deploy \ + -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ + -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ + -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ + --batch-mode --errors --fail-at-end \ + --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simbank-tests-build.log + + - name: Upload galasa-simbank-tests Maven Build Log + if: always() + uses: actions/upload-artifact@v4 + with: + name: galasa-simbank-tests-build-log + path: galasa-simbank-tests-build.log + + - name: Login to Github Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata for Simplatform maven artefacts image + id: metadata-simplatform + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/simplatform-maven-artefacts + + - name: Build Simplatform image for development Maven registry + id: build-simplatform + uses: docker/build-push-action@v5 + with: + context: . + file: dockerfiles/dockerfile.simplatform + push: true + tags: ${{ steps.metadata-simplatform.outputs.tags }} + labels: ${{ steps.metadata-simplatform.outputs.labels }} + build-args: | + baseVersion=latest + dockerRepository=ghcr.io + branch=main + + - name: Extract metadata for Simplatform jar image + id: metadata-simplatform-jar + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/simplatform-jar + + - name: Build simplatform jar image + id: build-simplatform-jar + uses: docker/build-push-action@v5 + with: + context: . + file: dockerfiles/dockerfile.simplatform-amd64 + push: true + tags: ${{ steps.metadata-simplatform-jar.outputs.tags }} + labels: ${{ steps.metadata-simplatform-jar.outputs.labels }} + + - name: Recycle application in ArgoCD + env: + ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }} + run: | + docker run --env ARGOCD_AUTH_TOKEN=${{ env.ARGOCD_AUTH_TOKEN }} --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/argocdcli:main app actions run gh-simplatform restart --kind Deployment --resource-name simplatform-gh --server argocd.galasa.dev + + # Wait for the application to show as healthy in ArgoCD + - name: Wait for app health in ArgoCD + env: + ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }} + run: | + docker run --env ARGOCD_AUTH_TOKEN=${{ env.ARGOCD_AUTH_TOKEN }} --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/argocdcli:main app wait gh-simplatform --resource apps:Deployment:simplatform-gh --health --server argocd.galasa.dev + \ No newline at end of file diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml new file mode 100644 index 0000000..fbe7706 --- /dev/null +++ b/.github/workflows/pr-build.yaml @@ -0,0 +1,63 @@ +name: PR Build + +on: + pull_request: + branches: [main] + +jobs: + build-simplatform: + name: Building Simplatform + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'semeru' + cache: maven + + - name: Print Githash + run: | + echo $GITHUB_SHA > ./simplatform.githash + + - name: Building galasa-simplatform-application using maven + run: | + mvn -f galasa-simplatform-application/pom.xml -X deploy -Dgpg.skip=true \ + -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ + -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ + -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ + --batch-mode --errors --fail-at-end \ + --settings ${{github.workspace}}/settings.xml + + - name: Building galasa-simbank-tests using maven + run: | + mvn -f galasa-simbank-tests/pom.xml -X deploy -Dgpg.skip=true \ + -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ + -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ + -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ + --batch-mode --errors --fail-at-end \ + --settings ${{github.workspace}}/settings.xml + + - name: Build Simplatform image for testing + uses: docker/build-push-action@v5 + with: + context: . + file: dockerfiles/dockerfile.simplatform + load: true + tags: simplatform-maven-artefacts:test + build-args: | + baseVersion=latest + dockerRepository=ghcr.io + branch=main + + - name: Build Simplatform jar image for testing + uses: docker/build-push-action@v5 + with: + context: . + file: dockerfiles/dockerfile.simplatform-amd64 + load: true + tags: simplatform-jar:test \ No newline at end of file diff --git a/dockerfiles/dockerfile.simplatform b/dockerfiles/dockerfile.simplatform new file mode 100644 index 0000000..d4da611 --- /dev/null +++ b/dockerfiles/dockerfile.simplatform @@ -0,0 +1,11 @@ +ARG baseVersion +ARG dockerRepository +FROM ${dockerRepository}/galasa-dev/base-image:${baseVersion} + +ARG branch + +RUN sed -i "s/--branchname--/${branch}/" /usr/local/apache2/conf/httpd.conf +RUN sed -i 's/--repositoryname--/simplatform/' /usr/local/apache2/conf/httpd.conf + +COPY repo/ /usr/local/apache2/htdocs/ +COPY simplatform.githash /usr/local/apache2/htdocs/simplatform.githash \ No newline at end of file diff --git a/dockerfiles/dockerfile.simplatform-amd64 b/dockerfiles/dockerfile.simplatform-amd64 new file mode 100644 index 0000000..3ca78d3 --- /dev/null +++ b/dockerfiles/dockerfile.simplatform-amd64 @@ -0,0 +1,20 @@ +FROM harbor.galasa.dev/docker_proxy_cache/library/openjdk:11-jdk + +RUN mkdir /galasa + +RUN useradd -u 1000 -d /galasa galasa && \ + chown -R galasa:galasa /galasa + +WORKDIR /galasa + +USER galasa + +COPY galasa-simplatform-application/galasa-simplatform-3270/target/galasa-simplatform-0.24.0.jar /galasa/simplatform.jar + +VOLUME /galasa/.galasa +VOLUME /galasa/load + +EXPOSE 2080/tcp +EXPOSE 2023/tcp +EXPOSE 2027/tcp +EXPOSE 2040/tcp \ No newline at end of file From b948ef817038ed30ec6dd90cf18c50c6812b958f Mon Sep 17 00:00:00 2001 From: dhruv Date: Thu, 22 Aug 2024 19:24:56 +0530 Subject: [PATCH 2/2] made required changes Signed-off-by: dhruv --- .github/workflows/build.yaml | 6 ++++-- .github/workflows/pr-build.yaml | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 4c2a5d7..2d4b73f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -39,11 +39,12 @@ jobs: --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simplatform-application-build.log - name: Upload galasa-simplatform-application Maven Build Log - if: always() + if: failure() uses: actions/upload-artifact@v4 with: name: galasa-simplatform-application-build-log path: galasa-simplatform-application-build.log + retention-days: 7 - name: Building galasa-simbank-tests using maven run: | @@ -56,11 +57,12 @@ jobs: --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simbank-tests-build.log - name: Upload galasa-simbank-tests Maven Build Log - if: always() + if: failure() uses: actions/upload-artifact@v4 with: name: galasa-simbank-tests-build-log path: galasa-simbank-tests-build.log + retention-days: 7 - name: Login to Github Container Registry uses: docker/login-action@v3 diff --git a/.github/workflows/pr-build.yaml b/.github/workflows/pr-build.yaml index fbe7706..15a895e 100644 --- a/.github/workflows/pr-build.yaml +++ b/.github/workflows/pr-build.yaml @@ -26,21 +26,39 @@ jobs: - name: Building galasa-simplatform-application using maven run: | + set -o pipefail mvn -f galasa-simplatform-application/pom.xml -X deploy -Dgpg.skip=true \ -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ --batch-mode --errors --fail-at-end \ - --settings ${{github.workspace}}/settings.xml + --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simplatform-application-build.log + + - name: Upload galasa-simplatform-application Maven Build Log + if: failure() + uses: actions/upload-artifact@v4 + with: + name: galasa-simplatform-application-build-log + path: galasa-simplatform-application-build.log + retention-days: 7 - name: Building galasa-simbank-tests using maven run: | + set -o pipefail mvn -f galasa-simbank-tests/pom.xml -X deploy -Dgpg.skip=true \ -Dgalasa.source.repo=https://development.galasa.dev/gh/maven-repo/obr \ -Dgalasa.central.repo=https://repo.maven.apache.org/maven2/ \ -Dgalasa.release.repo=file:${{ github.workspace }}/repo \ --batch-mode --errors --fail-at-end \ - --settings ${{github.workspace}}/settings.xml + --settings ${{github.workspace}}/settings.xml 2>&1 | tee galasa-simbank-tests-build.log + + - name: Upload galasa-simbank-tests Maven Build Log + if: failure() + uses: actions/upload-artifact@v4 + with: + name: galasa-simbank-tests-build-log + path: galasa-simbank-tests-build.log + retention-days: 7 - name: Build Simplatform image for testing uses: docker/build-push-action@v5