From b3d79c884ac18b3e38ff28f4d318170ca44d58ea Mon Sep 17 00:00:00 2001 From: Zafei-Erin <86716431+Zafei-Erin@users.noreply.github.com> Date: Thu, 22 Feb 2024 01:02:36 +0800 Subject: [PATCH] try to test be workflows (#4) * try to test be workflows * aws instance id * aws * rename * aws * aws * aws * update names * ci * tab * ci * test be-ci * ci * ci * test be ci * be ci * test be ci * be ci * be ci * fe * be * ci * ci * ci --- .github/workflows/Backend-cd.yml | 35 ++++++++++ .github/workflows/Backend-ci .yml | 64 +++++++++++++++++++ .../workflows/{ci.yaml => Frontend-ci.yaml} | 19 ++++-- .github/workflows/production.yml | 35 ---------- .github/workflows/staging.yml | 35 ---------- backend/src/index.ts | 1 + frontend/src/main.tsx | 1 + 7 files changed, 113 insertions(+), 77 deletions(-) create mode 100644 .github/workflows/Backend-cd.yml create mode 100644 .github/workflows/Backend-ci .yml rename .github/workflows/{ci.yaml => Frontend-ci.yaml} (53%) delete mode 100644 .github/workflows/production.yml delete mode 100644 .github/workflows/staging.yml diff --git a/.github/workflows/Backend-cd.yml b/.github/workflows/Backend-cd.yml new file mode 100644 index 0000000..540cf8a --- /dev/null +++ b/.github/workflows/Backend-cd.yml @@ -0,0 +1,35 @@ +name: Backend-cd + +on: + pull_request: + types: [labeled] + +jobs: + deploy-git: + if: "${{ github.event.label.name == 'prod: backend' }}" + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Remove deploy label + uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: "prod: backend" + + deploy-aws: + needs: deploy-git + runs-on: aws-nft + + steps: + - name: stop old image + run: sudo docker-compose stop + - name: remove old image + run: sudo docker-compose rm -f + - name: pull new image + run: sudo docker-compose pull + - name: run new image + run: sudo docker-compose up -d + - name: prune images + run: sudo docker image prune -af \ No newline at end of file diff --git a/.github/workflows/Backend-ci .yml b/.github/workflows/Backend-ci .yml new file mode 100644 index 0000000..6c3f4b2 --- /dev/null +++ b/.github/workflows/Backend-ci .yml @@ -0,0 +1,64 @@ +name: Backend-ci + +on: + push: + branches: [main] + paths: "backend/**" + pull_request: + types: [opened, synchronize, reopened] + paths: "backend/**" + +jobs: + git-ci: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Remove deploy label + uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: "deploy: backend" + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "npm" + cache-dependency-path: "backend/package-lock.json" + + - name: Install deps + run: npm install + working-directory: "backend" + + - name: Run ci + run: npm ci + working-directory: "backend" + + docker-push: + needs: git-ci + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: print location + run: pwd + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: ./backend + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/nft-mkp-api:latest diff --git a/.github/workflows/ci.yaml b/.github/workflows/Frontend-ci.yaml similarity index 53% rename from .github/workflows/ci.yaml rename to .github/workflows/Frontend-ci.yaml index 1345f48..34ac641 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/Frontend-ci.yaml @@ -1,32 +1,37 @@ -name: CI +name: Frontend-ci on: push: branches: [main] + paths: 'frontend/**' pull_request: types: [opened, synchronize, reopened] + paths: 'frontend/**' jobs: - test: + git-ci: runs-on: ubuntu-latest - strategy: - matrix: { dir: ["backend", "frontend", "smart_contract"] } steps: - name: Checkout repo uses: actions/checkout@v4 + + - name: Remove deploy label + uses: actions-ecosystem/action-remove-labels@v1 + with: + labels: "deploy: frontend" - name: Setup Node uses: actions/setup-node@v4 with: node-version: 18 cache: "npm" - cache-dependency-path: "**/package-lock.json" + cache-dependency-path: "frontend/package-lock.json" - name: Install deps run: npm install - working-directory: ${{ matrix.dir }} + working-directory: "frontend" - name: Run ci run: npm ci - working-directory: ${{ matrix.dir }} + working-directory: "frontend" diff --git a/.github/workflows/production.yml b/.github/workflows/production.yml deleted file mode 100644 index 8ad2466..0000000 --- a/.github/workflows/production.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Production - -on: - pull_request: - types: [labeled] - -jobs: - deploy-backend: - if: "${{ github.event.label.name == 'prod: backend' }}" - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Remove deploy label - uses: actions-ecosystem/action-remove-labels@v1 - with: - labels: "prod: backend" - - - name: Deploy to EC2 instance - uses: peterkimzz/aws-ssm-send-command@v1.1.1 - with: - aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - instance-ids: ${{ secrets.AWS_INSTANCE_ID }} - # Command execution location - working-directory: /home/ubuntu - command: | - sudo docker-compose stop - sudo docker-compose rm -f - sudo docker-compose pull - sudo docker-compose up -d - sudo docker image prune -af diff --git a/.github/workflows/staging.yml b/.github/workflows/staging.yml deleted file mode 100644 index 98d852c..0000000 --- a/.github/workflows/staging.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Staging - -on: - pull_request: - types: [labeled] - -jobs: - deploy-backend: - if: "${{ github.event.label.name == 'deploy: backend' }}" - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Remove deploy label - uses: actions-ecosystem/action-remove-labels@v1 - with: - labels: "deploy: backend" - - - name: Login to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: ./backend - push: true - tags: ${{ secrets.DOCKERHUB_USERNAME }}/nft-mkp-api:latest diff --git a/backend/src/index.ts b/backend/src/index.ts index fa9debc..73d0459 100644 --- a/backend/src/index.ts +++ b/backend/src/index.ts @@ -23,3 +23,4 @@ app.use(errorHandler); app.use(router); app.listen(port, () => console.log(`Server running on port ${port}`)); + diff --git a/frontend/src/main.tsx b/frontend/src/main.tsx index 929a2d0..171e3cb 100644 --- a/frontend/src/main.tsx +++ b/frontend/src/main.tsx @@ -12,3 +12,4 @@ ReactDOM.createRoot(document.getElementById("root")!).render( ); +