diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 08cbef3..602209d 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,57 +3,38 @@ on: push: branches: [main] workflow_dispatch: +env: + DOMAIN_NAME: 'www.tokenpage.xyz' + DIST_DIR: './dist' jobs: - deploy-app: + deploy: runs-on: ubuntu-latest - env: - DOCKER_IMAGE: ghcr.io/${{ github.repository }}-app:latest steps: - - name: Check out the repo - uses: actions/checkout@v2 - - name: Login to GitHub container registry - uses: docker/login-action@v2 + - name: Checkout Code + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Build docker image - uses: docker/build-push-action@v2 + node-version: 20 + cache: npm + - name: Install Dependencies + run: npm ci + - name: Build Site + run: npm run build + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 with: - context: . - push: true - cache-from: type=gha,scope=app - cache-to: type=gha,mode=max,scope=app - tags: ${{ env.DOCKER_IMAGE }} - run-app: - needs: deploy-app - runs-on: ubuntu-latest - env: - NAME: tokenpage-landing-app - DOCKER_IMAGE: ghcr.io/${{ github.repository }}-app:latest - steps: - - name: executing remote ssh commands - uses: appleboy/ssh-action@master - with: - host: ${{ secrets.MDTPBOX_URL }} - username: ${{ secrets.MDTPBOX_USER }} - key: ${{ secrets.MDTPBOX_SSH_KEY }} - port: ${{ secrets.MDTPBOX_PORT }} - envs: DOCKER_IMAGE,NAME - script_stop: true - script: | - url="www.tokenpage.xyz" - docker pull ${DOCKER_IMAGE} - docker stop ${NAME} && docker rm ${NAME} || true - docker run \ - --name ${NAME} \ - --detach \ - --publish-all \ - --restart unless-stopped \ - --env NAME=${NAME} \ - --env VIRTUAL_HOST=${url} \ - --env LETSENCRYPT_HOST=${url} \ - --env-file ~/.${NAME}.vars \ - ${DOCKER_IMAGE} + aws-access-key-id: ${{ secrets.SITE_DEPLOYER_AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.SITE_DEPLOYER_AWS_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.SITE_DEPLOYER_AWS_REGION }} + - name: Sync to S3 + run: | + aws s3 sync \ + --delete \ + ${{ env.DIST_DIR }} \ + s3://${{ secrets.SITE_DEPLOYMENT_S3_BUCKET_NAME }}/${{ env.DOMAIN_NAME }}/ + - name: Invalidate CloudFront Cache + run: | + aws cloudfront create-invalidation \ + --distribution-id ${{ secrets.SITE_DEPLOYMENT_CLOUDFRONT_ID }} \ + --paths "/${{ env.DOMAIN_NAME }}/*" diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index b4eb6de..8919b28 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -3,18 +3,17 @@ on: pull_request: branches: [main] jobs: - build-app: + build-site: runs-on: ubuntu-latest - env: - DOCKER_IMAGE: build steps: - name: Check out the repo - uses: actions/checkout@v2 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - name: Build docker image - uses: docker/build-push-action@v2 + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 with: - context: . - cache-from: type=gha,scope=app - cache-to: type=gha,mode=max,scope=app + node-version: 20 + cache: npm + - name: Install dependencies + run: npm ci + - name: Build static site + run: npm run build