From 47125999b630f243650e0fdd0b2d5bcd54e1a77a Mon Sep 17 00:00:00 2001 From: Markus Nyman Date: Sat, 11 Nov 2023 15:40:06 +0200 Subject: [PATCH] build frontend in action --- .github/workflows/docker-image.yml | 79 +++++++++++++++++++++++++++--- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index f1609dc..89acb4c 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -2,20 +2,82 @@ name: Docker Image CI on: push: - branches: ["master"] + branches: ["master", "actions"] pull_request: branches: ["master"] jobs: - build: + build-weihua: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - - name: Build the Docker image + - name: Build the weihua Docker image working-directory: backend/pocketbase - run: docker build . --file Dockerfile --tag weihua:latest + run: | + docker build . --file Dockerfile --tag weihua:latest + mkdir -p artifacts/weihua/ + docker save weihua:latest | bzip2 > artifacts/weihua/weihua.tar.bz2 + - name: Temporarily save Docker image + uses: actions/upload-artifact@v2 + with: + name: weihua-artifact + path: backend/pocketbase/artifacts/weihua + retention-days: 1 + + build-frontend: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: 20 + - uses: pnpm/action-setup@v2 + with: + version: 8 + run_install: false + - name: Get pnpm store directory + run: | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + - uses: actions/cache@v3 + name: Setup pnpm cache + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- + + - name: Install dependencies + working-directory: dance-app + run: pnpm install + + - name: Build dance-app + working-directory: dance-app + run: pnpm build + + - name: Temporarily save Docker image + uses: actions/upload-artifact@v2 + with: + name: dance-app-artifact + path: dance-app/dist + retention-days: 1 + + deploy-backend: + runs-on: ubuntu-latest + needs: [build-weihua, build-frontend] + steps: + - uses: actions/checkout@v3 + + - name: Retrieve saved weihua image + uses: actions/download-artifact@v2 + with: + name: weihua-artifact + + - name: Retrieve dance-app + uses: actions/download-artifact@v2 + with: + name: dance-app-artifact - name: Install ssh keys @@ -25,8 +87,9 @@ jobs: install -m 600 -D /dev/null ~/.ssh/id_rsa echo "${{ secrets.M }}" > ~/.ssh/id_rsa ssh-keyscan -H junction.nyman.dev > ~/.ssh/known_hosts - - - name: Copy image to server - run: docker save weihua:latest | bzip2 | ssh root@junction.nyman.dev "docker load && cd weihua && docker compose up -d && exit" + - name: Copy weihua to server + run: ssh root@junction.nyman.dev "docker load && cd weihua && docker compose up -d && exit" < artifacts/weihua/weihua.tar.bz2 + - name: Copy dance-app + run: scp -r dance-app/dist/* root@junction.nyman.dev:/usr/share/caddy - name: cleanup run: rm -rf ~/.ssh