chore(deps): update actions/checkout digest to 34e1148 (#388) #188
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
| name: Production | |
| on: | |
| push: | |
| branches: [main] | |
| env: | |
| AWS_REGION: ap-southeast-2 | |
| permissions: | |
| contents: read | |
| jobs: | |
| lint-format: | |
| name: Linting and Formatting Checks | |
| uses: ./.github/workflows/lint-and-format.yml | |
| permissions: | |
| contents: read | |
| build: | |
| needs: lint-format | |
| name: Build | |
| runs-on: ubuntu-24.04-arm | |
| environment: Production | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@900f2210b1d28bbbd0bd22d17926b9e224e8f231 | |
| - name: Configure AWS credentials | |
| uses: aws-actions/configure-aws-credentials@bc9489585819302995bb108bbd899b7975f40303 | |
| with: | |
| role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
| role-session-name: ${{ secrets.AWS_ROLE_SESSION_NAME }} | |
| aws-region: ${{ env.AWS_REGION }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd | |
| - name: Cache Docker layers | |
| uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb | |
| with: | |
| path: /tmp/.buildx-cache | |
| key: ${{ runner.os }}-buildx-${{ github.sha }} | |
| restore-keys: | | |
| ${{ runner.os }}-buildx- | |
| - name: Echo environment variables to .env.local | |
| run: | | |
| echo "NEXT_PUBLIC_KEYCLOAK_REDIRECT_URI=${{ secrets.NEXT_PUBLIC_KEYCLOAK_REDIRECT_URI }}" >> .env.local | |
| echo "NEXT_PUBLIC_AUTH_REALM=${{ secrets.NEXT_PUBLIC_AUTH_REALM }}" >> .env.local | |
| echo "NEXT_PUBLIC_CONTAINER_KEYCLOAK_ENDPOINT=${{ secrets.NEXT_PUBLIC_CONTAINER_KEYCLOAK_ENDPOINT }}" >> .env.local | |
| echo "NEXT_PUBLIC_LOCAL_KEYCLOAK_URL=${{ secrets.NEXT_PUBLIC_LOCAL_KEYCLOAK_URL }}" >> .env.local | |
| echo "NEXT_PUBLIC_DRIVE_LINK=${{ secrets.NEXT_PUBLIC_DRIVE_LINK }}" >> .env.local | |
| echo "NEXT_PUBLIC_UMAMI_WEBSITE_ID=${{ secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID }}" >> .env.local | |
| echo "NEXT_PUBLIC_PAYLOAD_URI=${{ secrets.NEXT_PUBLIC_PAYLOAD_URI }}" >> .env.local | |
| echo "NEXT_PUBLIC_DISCORD_CLIENT_ID=${{ secrets.NEXT_PUBLIC_DISCORD_CLIENT_ID }}" >> .env.local | |
| echo "NEXT_PUBLIC_DISCORD_CLIENT_SECRET=${{ secrets.NEXT_PUBLIC_DISCORD_CLIENT_SECRET }}" >> .env.local | |
| echo "NEXT_PUBLIC_DISCORD_REDIRECT_URI=${{ secrets.NEXT_PUBLIC_DISCORD_REDIRECT_URI }}" >> .env.local | |
| - name: Build Docker container | |
| env: | |
| PRODUCTION_BUILD: 'true' | |
| run: | | |
| docker buildx build \ | |
| --cache-from=type=local,src=/tmp/.buildx-cache \ | |
| --cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max \ | |
| --output type=docker,dest=csclub-website.tar \ | |
| --build-arg NEXT_PUBLIC_PAYLOAD_URI="${{ secrets.NEXT_PUBLIC_PAYLOAD_URI }}" \ | |
| --build-arg PRODUCTION_BUILD="true" \ | |
| --platform=linux/arm64 --file=Dockerfile -t csclub-website . | |
| gzip csclub-website.tar | |
| - name: Save Docker cache | |
| if: success() | |
| run: | | |
| rsync -a --delete /tmp/.buildx-cache-new/ /tmp/.buildx-cache/ | |
| - name: Copy image and compose file to S3 | |
| run: | | |
| aws s3 cp ./csclub-website.tar.gz s3://${{ secrets.AWS_S3_BUCKET }}/website/ | |
| aws s3 cp ./docker-compose.yml s3://${{ secrets.AWS_S3_BUCKET }}/website/ | |
| deploy: | |
| needs: build | |
| name: Deploy | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| environment: Production | |
| steps: | |
| - name: Deploy on EC2 | |
| env: | |
| KEY: ${{ secrets.SSH_EC2_KEY }} | |
| HOSTNAME: ${{ secrets.SSH_EC2_HOSTNAME }} | |
| USER: ${{ secrets.SSH_EC2_USER }} | |
| run: | | |
| echo "$KEY" > private_key && chmod 600 private_key | |
| ssh -v -o StrictHostKeyChecking=no -i private_key ${USER}@${HOSTNAME} ' | |
| cd ~/website | |
| aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/website/csclub-website.tar.gz . | |
| aws s3 cp s3://${{ secrets.AWS_S3_BUCKET }}/website/docker-compose.yml . | |
| docker load -i csclub-website.tar.gz | |
| docker compose up -d | |
| ' |