From 3c2047eb4f1ee0418c45df2ca6843c784e495eb0 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 10:40:07 -0500 Subject: [PATCH 1/9] BIL-6: adding script to help quick merging --- scripts/mr_create_merge.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 scripts/mr_create_merge.sh diff --git a/scripts/mr_create_merge.sh b/scripts/mr_create_merge.sh new file mode 100644 index 00000000..c54f93ea --- /dev/null +++ b/scripts/mr_create_merge.sh @@ -0,0 +1,15 @@ +#!/bin/bash +set -e + +BASE_BRANCH="develop" +FEATURE_BRANCH="BIL-6-update-fixed" +PR_TITLE="BIL-6: Building Workflow" +PR_BODY="Building workflow" + +PR_URL=$(gh pr create --base "$BASE_BRANCH" --head "$FEATURE_BRANCH" --title "$PR_TITLE" --body "$PR_BODY" | grep "https") + +echo "Pull request created: $PR_URL" + +# Merge the pull request +gh pr merge "$PR_URL" --merge --admin +echo "Pull request merged and branch deleted." \ No newline at end of file From 243e9f5a8f9a823f90bc136225922f037b99f7f8 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 10:43:59 -0500 Subject: [PATCH 2/9] BIL-6: oops --- .github/workflows/develop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index acded584..d7fd4005 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -174,6 +174,8 @@ jobs: needs: - frontend_oci_image steps: + - uses: actions/checkout@v4 + - name: Remote Command on Infrastructure uses: ./.github/actions/remote-command with: From 3c7fa5e509c7d0e75ebddd96fb948afffaf7e5ea Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 11:28:12 -0500 Subject: [PATCH 3/9] BIL-6: lets try this out --- .github/actions/remote-command/action.yml | 32 ++++++++++++++++++----- .github/workflows/develop.yml | 8 ++++-- 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/.github/actions/remote-command/action.yml b/.github/actions/remote-command/action.yml index bd08b2cb..91e0e4e8 100644 --- a/.github/actions/remote-command/action.yml +++ b/.github/actions/remote-command/action.yml @@ -1,20 +1,38 @@ name: Remote Command description: Run a command on one of our servers. + inputs: - server: - description: Name of the server + # bastion + bastion_private_key: + description: The private SSH key of the bastion + required: true + bastion_ssh_user: + description: The user of the bastion + required: true + bastion_ssh_host: + description: The host of the bastion + required: true + + # deployment server + deployment_private_key: + description: The private SSH key for the deployment server required: true - user: + deployment_ssh_user: description: Name of the user on the server required: true + deployment_server: + description: Name of the server + required: true + + # other command: - description: Shell command to run for develop + description: Shell command to run required: true runs: using: composite steps: - name: Write Keys - run: mkdir -p ~/.ssh && echo "${{secrets.BASTION_PRIVATE_KEY}}" >> ~/.ssh/bastion && echo "${{secrets.DEPLOYMENT_PRIVATE_KEY}}" >> ~/.ssh/deployment + run: mkdir -p ~/.ssh && echo "${{ inputs.bastion_private_key}}" >> ~/.ssh/bastion && echo "${{ inputs.deployment_private_key}}" >> ~/.ssh/deployment shell: bash - name: Set Key Permissions @@ -31,9 +49,9 @@ runs: shell: bash - name: Acknowledge Host Key on Bastion - run: ssh -T -i ~/.ssh/bastion -o "StrictHostKeyChecking no" -p 2222 ${{secrets.BASTION_SSH_USER}}@${{secrets.BASTION_HOST}} + run: ssh -T -i ~/.ssh/bastion -o "StrictHostKeyChecking no" -p 2222 ${{ inputs.bastion_ssh_user}}@${{ inputs.bastion_ssh_host}} shell: bash - name: Run Command - run: ssh -o "StrictHostKeyChecking no" -A -J ${{secrets.BASTION_SSH_USER}}@${{secrets.BASTION_HOST}}:2222 ${{inputs.user}}@${{inputs.server}}.kerosenelabs.com "${{inputs.command}}" + run: ssh -o "StrictHostKeyChecking no" -A -J ${{ inputs.bastion_ssh_user }}@${{ inputs.bastion_ssh_host}}:2222 ${{ inputs.deployments_ssh_user }}@${{ inputs.deployment_server }}.kerosenelabs.com "${{ inputs.command }}" shell: bash diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index d7fd4005..71551505 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -179,6 +179,10 @@ jobs: - name: Remote Command on Infrastructure uses: ./.github/actions/remote-command with: - server: mars1d - user: infra + bastion_private_key: ${{ secrets.BASTION_PRIVATE_KEY }} + bastion_ssh_user: ${{ secrets.BASTION_SSH_USER }} + bastion_ssh_host: ${{ secrets.BASTION_HOST }} + deployment_private_key: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} + deployment_user: infra + deployment_server: mars1d command: ls \ No newline at end of file From 2e0e44eb5b60032c3bde669690bec443d40c85e3 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 11:30:41 -0500 Subject: [PATCH 4/9] BIL-6: fixing typo --- .github/actions/remote-command/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/remote-command/action.yml b/.github/actions/remote-command/action.yml index 91e0e4e8..e3e6febf 100644 --- a/.github/actions/remote-command/action.yml +++ b/.github/actions/remote-command/action.yml @@ -53,5 +53,5 @@ runs: shell: bash - name: Run Command - run: ssh -o "StrictHostKeyChecking no" -A -J ${{ inputs.bastion_ssh_user }}@${{ inputs.bastion_ssh_host}}:2222 ${{ inputs.deployments_ssh_user }}@${{ inputs.deployment_server }}.kerosenelabs.com "${{ inputs.command }}" + run: ssh -o "StrictHostKeyChecking no" -A -J ${{ inputs.bastion_ssh_user }}@${{ inputs.bastion_ssh_host}}:2222 ${{ inputs.deployment_ssh_user }}@${{ inputs.deployment_server }}.kerosenelabs.com "${{ inputs.command }}" shell: bash From acfd4f1fb975750fbc233bde2846b97944d9dd61 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 11:33:56 -0500 Subject: [PATCH 5/9] BIL-6: fixing typo --- .github/workflows/develop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 71551505..e44645de 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -183,6 +183,6 @@ jobs: bastion_ssh_user: ${{ secrets.BASTION_SSH_USER }} bastion_ssh_host: ${{ secrets.BASTION_HOST }} deployment_private_key: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} - deployment_user: infra + deployment_ssh_user: infra deployment_server: mars1d command: ls \ No newline at end of file From dac80a47b0f85840f58f592c56de76e089a3290d Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 11:41:43 -0500 Subject: [PATCH 6/9] BIL-6: changing deployment command --- .github/workflows/develop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index e44645de..ab97d0a1 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -185,4 +185,4 @@ jobs: deployment_private_key: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} deployment_ssh_user: infra deployment_server: mars1d - command: ls \ No newline at end of file + command: cd billtracker && docker compose pull frontend backend && docker compose up frontend backend -d \ No newline at end of file From 5ffcfe2374e778379c1a9d07d2e6cb6559f1d84c Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 11:42:54 -0500 Subject: [PATCH 7/9] BIL-6: adding env and needs --- .github/workflows/develop.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index ab97d0a1..0fb2c4d8 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -166,13 +166,15 @@ jobs: cache-from: type=gha cache-to: type=gha,mode=max - frontend_deploy: + deploy: runs-on: ubuntu-24.04 defaults: run: working-directory: ./frontend needs: - frontend_oci_image + - backend_oci_image + environment: develop steps: - uses: actions/checkout@v4 From 65479519e861db01dfa94741624cac4d0c1efef3 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 12:17:16 -0500 Subject: [PATCH 8/9] BIL-6: tweaking --- .github/workflows/develop.yml | 9 +- .github/workflows/main.yml | 187 ++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/main.yml diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 0fb2c4d8..5f45e598 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -111,12 +111,9 @@ jobs: - name: Set Target uses: ./.github/actions/set-target - - name: Build Distributable for Target - uses: ./.github/actions/target-specific-command - with: - working_directory: ./frontend - production: npm run build -- --mode=production - develop: npm run build -- --mode=develop + - name: Build Distributable + run: npm run build -- --mode=develop + - run: ls - name: Upload Artifact uses: actions/upload-artifact@v4 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..cfb87579 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,187 @@ +name: Build +on: + push: + branches: + - develop + tags: + - "v*" + +jobs: + backend_dist: + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + actions: read + security-events: write + defaults: + run: + working-directory: ./backend + steps: + - uses: actions/checkout@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: "21" + distribution: "corretto" + server-id: github + settings-path: ${{ github.workspace }} + cache: "maven" + + - name: Cache Maven dependencies + uses: actions/cache@v3 + with: + path: ~/.m2/repository + key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-maven- + + - name: Build with Maven + run: ./mvnw -B package --file pom.xml + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: backend + path: | + ./backend/target/billtracker-backend-1.0.0.jar + + backend_oci_image: + runs-on: ubuntu-24.04 + defaults: + run: + working-directory: ./backend + needs: + - backend_dist + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.ACCESS_TOKEN }} + + - name: Set Target + uses: ./.github/actions/set-target + + - uses: actions/download-artifact@v4 + with: + name: backend + path: ./backend + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./backend + push: true + tags: ghcr.io/kerosene-labs/billtracker-backend:${{ env.TARGET }} + cache-from: type=gha + cache-to: type=gha,mode=max + + frontend_dist: + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + actions: read + security-events: write + defaults: + run: + working-directory: ./frontend + steps: + - uses: actions/checkout@v4 + + - name: Cache npm dependencies + uses: actions/cache@v3 + with: + path: ~/.npm + key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-node- + + - name: Install NPM Packages + run: npm i + + - name: Set Target + uses: ./.github/actions/set-target + + - name: Build Distributable + run: npm run build -- --mode=production + + - run: ls + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: frontend + path: ./frontend/build + + frontend_oci_image: + runs-on: ubuntu-24.04 + defaults: + run: + working-directory: ./frontend + needs: + - frontend_dist + steps: + - uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.ACCESS_TOKEN }} + + - name: Set Target + uses: ./.github/actions/set-target + + - uses: actions/download-artifact@v4 + with: + name: frontend + path: ./frontend/build + + - name: Install NPM Packages + run: npm i + + - run: ls + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: ./frontend + push: true + tags: ghcr.io/kerosene-labs/billtracker-frontend:${{ env.TARGET }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + runs-on: ubuntu-24.04 + defaults: + run: + working-directory: ./frontend + needs: + - frontend_oci_image + - backend_oci_image + environment: develop + steps: + - uses: actions/checkout@v4 + + - name: Remote Command on Infrastructure + uses: ./.github/actions/remote-command + with: + bastion_private_key: ${{ secrets.BASTION_PRIVATE_KEY }} + bastion_ssh_user: ${{ secrets.BASTION_SSH_USER }} + bastion_ssh_host: ${{ secrets.BASTION_HOST }} + deployment_private_key: ${{secrets.DEPLOYMENT_PRIVATE_KEY}} + deployment_ssh_user: infra + deployment_server: mars1d + command: cd billtracker && docker compose pull frontend backend && docker compose up frontend backend -d \ No newline at end of file From 6a1ec94ae542bf2fa06061296e8ece4bd9b56dbd Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 12:18:32 -0500 Subject: [PATCH 9/9] BIL-6: tweaking --- .github/workflows/develop.yml | 4 +--- .github/workflows/main.yml | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 5f45e598..d89436bc 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -1,10 +1,8 @@ -name: Build +name: CI/CD - Develop on: push: branches: - develop - tags: - - "v*" jobs: backend_dist: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cfb87579..29b02beb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,8 +1,6 @@ -name: Build +name: CI/CD - Production on: push: - branches: - - develop tags: - "v*"