Merge pull request #420 from Game-as-a-Service/refactor/room #282
This file contains 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: Build and Deploy to AWS | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
env: | |
APPLICATION_FOLDER: ~/game-lobby/frontend | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
jobs: | |
build_and_deploy: | |
name: Build and Test and Deploy to AWS EC2 | |
runs-on: ubuntu-latest | |
environment: production | |
timeout-minutes: 10 | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
# the ARN (Amazon Resource Name) of the IAM role that should be assumed. | |
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} | |
# sets the session name used when assuming the role. | |
role-session-name: github-runner-build-and-deploy | |
aws-region: us-east-1 | |
- name: Login to AWS ECR | |
id: login-ecr-public | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
# an argument to the amazon-ecr-login action indicating that the ECR registry you are logging into is public. | |
registry-type: public | |
- name: Git checkout | |
uses: actions/checkout@v3 | |
- name: Cache dependencies | |
id: cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
node_modules | |
~/.cache/Cypress | |
key: deps-node-modules-${{ hashFiles('**/yarn.lock') }} | |
- name: Install dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: yarn install --frozen-lockfile | |
- name: Test | |
run: yarn test | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
with: | |
driver: docker-container | |
driver-opts: | | |
image=moby/buildkit:v0.9.3 | |
network=host | |
- name: Build and push Docker images | |
uses: docker/build-push-action@v4 | |
with: | |
context: '.' | |
file: ./docker/Dockerfile.production | |
push: true | |
tags: | | |
${{ vars.AWS_ECR_URI }}/${{ vars.AWS_ECR_REPOSITORY_NAME }}:latest | |
${{ vars.AWS_ECR_URI }}/${{ vars.AWS_ECR_REPOSITORY_NAME }}:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha | |
# Restart systemd service | |
- name: Run Application | |
uses: appleboy/ssh-action@v0.1.10 | |
with: | |
host: ${{ vars.EC2_HOST }} | |
username: ${{ vars.EC2_USERNAME }} | |
port: ${{ vars.EC2_PORT }} | |
key: ${{ secrets.EC2_KEY }} | |
script: | | |
uname -a | |
whoami | |
pwd | |
sudo systemctl restart game-lobby | |