From fb34cb0202d85f036f4c29484678f4c42abd0938 Mon Sep 17 00:00:00 2001 From: Hoang-Nguyen-Huy Date: Wed, 20 Nov 2024 16:46:09 +0700 Subject: [PATCH] [PBS-108][HoangHN] feat: add cicd --- .github/workflows/cicd.yaml | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 .github/workflows/cicd.yaml diff --git a/.github/workflows/cicd.yaml b/.github/workflows/cicd.yaml new file mode 100644 index 0000000..1320db2 --- /dev/null +++ b/.github/workflows/cicd.yaml @@ -0,0 +1,80 @@ +name: POD Booking System Client CICD + +on: + push: + branches: ['main', 'develop'] + pull_request: + branches: ['main', 'develop'] + +jobs: + build: + name: Build and analyze + runs-on: ubuntu-22.04 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 20 + + - name: Install dependencies + uses: bahmutov/npm-install@v1 + + - name: Build project + run: npm run build + env: + VITE_FIREBASE_API_KEY: ${{ secrets.FIREBASE_API_KEY }} + VITE_FIREBASE_AUTH_DOMAIN: ${{ secrets.FIREBASE_AUTH_DOMAIN }} + VITE_FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }} + VITE_FIREBASE_STORAGE_BUCKET: ${{ secrets.FIREBASE_STORAGE_BUCKET }} + VITE_FIREBASE_MESSAGING_SENDER_ID: ${{ secrets.FIREBASE_MESSAGING_SENDER_ID }} + VITE_FIREBASE_APP_ID: ${{ secrets.FIREBASE_APP_ID }} + VITE_FIREBASE_MEASUREMENT_ID: ${{ secrets.FIREBASE_MEASUREMENT_ID }} + VITE_API_BASE_URL: ${{ secrets.API_BASE_URL }} + + - name: Upload production-ready build files + uses: actions/upload-artifact@v4 + with: + name: production-files + path: ./dist + + deploy: + name: Deploy to Server + runs-on: ubuntu-22.04 + needs: build # Job deploy depend on job build + + steps: + - name: Check out code + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Build and tag Docker image + run: | + docker build -t hoanghuynguyen/pod-booking-system-client:latest . + + - name: Push Docker image to Docker Hub + run: | + docker push hoanghuynguyen/pod-booking-system-client:latest + + - name: Deploy to server + uses: appleboy/ssh-action@v0.1.8 + with: + host: ${{ secrets.SERVER_HOST }} + username: ${{ secrets.SERVER_USER }} + key: ${{ secrets.SERVER_SSH_KEY }} + script: | + cd swp + docker pull hoanghuynguyen/pod-booking-system-client:latest + docker compose up -d + + # # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + # - name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6