From 697b9defd98226dc8ba8cdb743dabb84abb09399 Mon Sep 17 00:00:00 2001 From: hlafaille Date: Thu, 2 Jan 2025 10:25:23 -0500 Subject: [PATCH] BIL-6: testing new layout --- .github/workflows/build.yml | 167 --------------------------------- .github/workflows/deploy.yml | 15 --- .github/workflows/develop.yml | 170 +++++++++++++++++++--------------- 3 files changed, 93 insertions(+), 259 deletions(-) delete mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index e930f34e..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,167 +0,0 @@ -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 for Target - uses: ./.github/actions/target-specific-command - with: - working_directory: ./frontend - production: npm run build -- --mode=production - develop: npm run build -- --mode=develop - - 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 \ No newline at end of file diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 618d24e8..00000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Deploy -on: - workflow_dispatch: - workflow_run: - workflows: ["Build"] - types: [completed] -jobs: - backend_oci_container: - runs-on: ubuntu-24.04 - defaults: - run: - working-directory: ./backend - environment: ${{ github.ref == 'refs/heads/main' && 'production' || 'develop' }} # pretty major shortcoming of GHA here... - steps: - - run: ls \ No newline at end of file diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 5c7c7942..c824ee2f 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -1,17 +1,14 @@ -name: Develop +name: Build on: - workflow_dispatch: -# on: - # push: - # branches: - # - main + push: + branches: + - develop + tags: + - "v*" jobs: - ### - ### BUILD DISTRIBUTABLE(S) - ### - build_backend: - runs-on: ubuntu-latest + backend_dist: + runs-on: ubuntu-24.04 permissions: contents: read packages: write @@ -31,7 +28,7 @@ jobs: server-id: github settings-path: ${{ github.workspace }} cache: "maven" - + - name: Cache Maven dependencies uses: actions/cache@v3 with: @@ -41,17 +38,54 @@ jobs: ${{ runner.os }}-maven- - name: Build with Maven - run: ./mvnw -B package --file pom.xml -Dproject.version=${{ github.sha }} - + run: ./mvnw -B package --file pom.xml + - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: backend path: | - ./backend/target/billtracker-backend-${{ github.sha }}.jar + ./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 - build_frontend: - runs-on: ubuntu-latest + frontend_dist: + runs-on: ubuntu-24.04 permissions: contents: read packages: write @@ -70,38 +104,36 @@ jobs: key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} restore-keys: | ${{ runner.os }}-node- + + - name: Install NPM Packages + run: npm i - - name: Navigate and Install Dependencies - run: npm i - - - name: Build Distributable - run: npm run build -- --mode develop + - 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 + - run: ls - name: Upload Artifact uses: actions/upload-artifact@v4 with: name: frontend - path: build + path: ./frontend/build - ### - ### PUBLISH PACKAGES - ### - publish_backend_oci_image: - runs-on: ubuntu-latest - needs: - - build_backend + frontend_oci_image: + runs-on: ubuntu-24.04 defaults: run: - working-directory: ./backend + working-directory: ./frontend + needs: + - frontend_dist steps: - uses: actions/checkout@v4 - - - uses: actions/download-artifact@v4 - with: - name: backend - path: ./backend - - - run: ls + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v3 @@ -111,52 +143,36 @@ jobs: 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: ./backend + context: ./frontend push: true - tags: ghcr.io/kerosene-labs/billtracker-backend:${{ github.sha }} - build-args: PROJECT_VERSION=${{ github.sha }} + tags: ghcr.io/kerosene-labs/billtracker-frontend:${{ env.TARGET }} cache-from: type=gha cache-to: type=gha,mode=max - - ### - ### DEPLOYMENT - ### - deploy: + + frontend_deploy: + runs-on: ubuntu-24.04 needs: - - publish_backend_oci_image - - build_frontend - runs-on: ubuntu-latest - environment: - name: develop + - frontend_oci_image steps: - - name: Write Keys - run: mkdir -p ~/.ssh && echo "${{secrets.BASTION_PRIVATE_KEY}}" >> ~/.ssh/bastion && echo "${{secrets.DEPLOYMENT_PRIVATE_KEY}}" >> ~/.ssh/deployment - - - name: Set Key Permissions - run: chmod 600 ~/.ssh/bastion && chmod 600 ~/.ssh/deployment - - - name: Start ssh-agent and add keys - run: | - eval "$(ssh-agent -s)" - ssh-add ~/.ssh/bastion - ssh-add ~/.ssh/deployment - echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> $GITHUB_ENV - echo "SSH_AGENT_PID=$SSH_AGENT_PID" >> $GITHUB_ENV - - - uses: actions/download-artifact@v4 - name: Download Frontend Artifact + - uses: ./.github/actions/remote-command with: - name: frontend - - - name: Acknowledge Host Key on Bastion - run: ssh -T -i ~/.ssh/bastion -o "StrictHostKeyChecking no" -p 2222 ${{secrets.BASTION_SSH_USER}}@${{secrets.BASTION_HOST}} - - - name: Update Frontend - run: scp -o "StrictHostKeyChecking no" -A -r -J ${{secrets.BASTION_SSH_USER}}@${{secrets.BASTION_HOST}}:2222 $PWD/* ${{secrets.DEPLOYMENT_SSH_USER}}@${{secrets.DEPLOYMENT_HOST}}:/home/infra/billtracker/frontend_content - - - name: Update Backend - run: ssh -o "StrictHostKeyChecking no" -A -J ${{secrets.BASTION_SSH_USER}}@${{secrets.BASTION_HOST}}:2222 ${{secrets.DEPLOYMENT_SSH_USER}}@${{secrets.DEPLOYMENT_HOST}} "bash -c \"cd billtracker && echo "export BILLTRACKER_VERSION=${{ github.sha }}" >> version.env && source version.env && docker compose pull backend && docker compose up -d backend\"" + server: mars1d + user: infra + command: ls \ No newline at end of file