From c1931c7b85bfd70368de51e338fe3c60e6b5d95a Mon Sep 17 00:00:00 2001 From: ihardy Date: Thu, 2 Jan 2025 09:38:15 -0500 Subject: [PATCH 1/2] first pass add some ci --- .github/workflows/build-deploy.yml | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 .github/workflows/build-deploy.yml diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml new file mode 100644 index 0000000..a9a8c43 --- /dev/null +++ b/.github/workflows/build-deploy.yml @@ -0,0 +1,78 @@ +name: Build and deploy listener + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + K8S_NAMESPACE: reshare + K8S_DEPLOYMENT: oai-pmh-viewer + JAVA_VERSION: 8 +on: + push: + +jobs: + build: + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + checks: write + pull-requests: write + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: ${{ env.JAVA_VERSION }} + distribution: 'adopt' + + - run: mvn install + + - name: Log in to the Container registry + #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' || contains(github.ref, 'release') }} + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' || contains(github.ref, 'release') }} + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # master and main + - name: Build and push Docker image + #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' }} + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + # extra tags for release branch + - name: Build and push Docker image + if: ${{ contains(github.ref, 'release') }} + uses: docker/build-push-action@v6 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:rc + labels: ${{ steps.meta.outputs.labels }} + + - name: Deploy latest to K8s + #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' }} + uses: actions-hub/kubectl@v1.21.2 + env: + KUBE_CONFIG: ${{ secrets.RESHARE_DEV_SA_KUBECONFIG }} + with: + args: + -n ${{ env.K8S_NAMESPACE }} rollout restart deployment ${{ env.K8S_DEPLOYMENT }} From 14d9cff94a7520e48571bdbe085797269856ac42 Mon Sep 17 00:00:00 2001 From: ihardy Date: Thu, 2 Jan 2025 09:43:16 -0500 Subject: [PATCH 2/2] adjust branch names --- .github/workflows/build-deploy.yml | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-deploy.yml b/.github/workflows/build-deploy.yml index a9a8c43..424f66c 100644 --- a/.github/workflows/build-deploy.yml +++ b/.github/workflows/build-deploy.yml @@ -30,8 +30,7 @@ jobs: - run: mvn install - name: Log in to the Container registry - #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' || contains(github.ref, 'release') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} uses: docker/login-action@v3 with: registry: ${{ env.REGISTRY }} @@ -39,8 +38,7 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Extract metadata (tags, labels) for Docker - #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' || contains(github.ref, 'release') }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || contains(github.ref, 'release') }} id: meta uses: docker/metadata-action@v5 with: @@ -48,8 +46,7 @@ jobs: # master and main - name: Build and push Docker image - #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} uses: docker/build-push-action@v6 with: context: . @@ -68,8 +65,7 @@ jobs: labels: ${{ steps.meta.outputs.labels }} - name: Deploy latest to K8s - #if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} - if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/DEVOPS-5009-ci' }} + if: ${{ github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' }} uses: actions-hub/kubectl@v1.21.2 env: KUBE_CONFIG: ${{ secrets.RESHARE_DEV_SA_KUBECONFIG }}