Deploy to Librarease frontend by @agmmtoo #126
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| run-name: Deploy to Librarease frontend by @${{ github.actor }} | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| Build: | |
| name: Build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v3 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@v1 | |
| with: | |
| aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| aws-region: ${{ secrets.AWS_REGION }} | |
| - name: export secret key | |
| run: | | |
| echo "${{ vars.production_ENV }}" > .env | |
| - name: Login to Amazon ECR | |
| id: login-ecr | |
| uses: aws-actions/amazon-ecr-login@v1 | |
| with: | |
| mask-password: "true" | |
| # This is a separate action that sets up buildx runner | |
| - name: Setup Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| # Use Github action cache | |
| - name: Cache Docker layers | |
| uses: actions/cache@v3 | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| # Create cache directory if it doesn't exist | |
| - name: Ensure cache directory exists | |
| run: mkdir -p /tmp/.buildx-cache | |
| - name: Build, tag, and push image to Amazon ECR | |
| id: build-image | |
| env: | |
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
| ECR_REPOSITORY: ${{ secrets.REPOSITORY }} | |
| IMAGE_TAG: ${{ vars.IMAGE_TAG }} | |
| run: | | |
| docker buildx build \ | |
| --cache-from type=local,src=/tmp/.buildx-cache \ | |
| --cache-to type=local,dest=/tmp/.buildx-cache-new,mode=max \ | |
| --tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG \ | |
| --push \ | |
| . | |
| # Temp fix for cache issue | |
| # https://github.com/docker/build-push-action/issues/252 | |
| # https://github.com/moby/buildkit/issues/1896 | |
| - name: Move cache | |
| run: | | |
| rm -rf /tmp/.buildx-cache | |
| mv /tmp/.buildx-cache-new /tmp/.buildx-cache | |
| deploy-frontend-service: | |
| name: Deploy to Frontend Service | |
| runs-on: ubuntu-latest | |
| needs: Build | |
| steps: | |
| - name: Git Checkout | |
| uses: actions/checkout@v2 | |
| - name: Echo Branch | |
| run: echo running on branch ${GITHUB_REF##*/} | |
| - uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Deploy to server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.PROD_SERVER_IP }} | |
| username: ${{ secrets.PROD_SERVER_USERNAME }} | |
| port: ${{ secrets.PORT }} | |
| key: ${{ secrets.PROD_SERVER_SSH_KEY }} | |
| script: | | |
| eval "$(ssh-agent -s)" | |
| ssh-add ~/.ssh/action | |
| cd /home/ubuntu/deploy | |
| bash deploy.sh |