feature: find game sort by times played #557
Workflow file for this run
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, workflow_dispatch ] | |
env: | |
JAR_FILENAME: Lobby-Platform | |
ARTIFACT_NAME: backend-app | |
SYSTEMD_SERVICE_NAME: lobby-platform | |
permissions: | |
id-token: write # This is required for requesting the JWT | |
contents: read # This is required for actions/checkout | |
jobs: | |
build: | |
name: Build on GitHub | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repo | |
- name: git checkout | |
uses: actions/checkout@v3 | |
# Setup JDK 17 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
# Maven Verify | |
- name: Maven Verify | |
run: mvn -B verify -DJAR_FILENAME=${{ env.JAR_FILENAME }} | |
# Dump GitHub Context | |
- name: Dump GitHub Context | |
env: | |
GITHUB_CONTEXT: ${{ toJSON(github) }} | |
run: | | |
echo '```' >> $GITHUB_STEP_SUMMARY | |
echo "$GITHUB_CONTEXT" >> $GITHUB_STEP_SUMMARY | |
echo '```' >> $GITHUB_STEP_SUMMARY | |
# Publish Artifact | |
- name: Upload Artifact | |
if: github.event_name == 'push' && github.ref_name == 'main' | |
uses: actions/upload-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: | | |
spring/target/${{ env.JAR_FILENAME }}.jar | |
docker/Dockerfile | |
docker-push: | |
name: Docker Push | |
runs-on: ubuntu-latest | |
needs: build | |
environment: production | |
if: github.event_name == 'push' && github.ref_name == 'main' | |
steps: | |
# Configure AWS credentials | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }} | |
role-session-name: github-runner-build-and-deploy | |
aws-region: us-east-1 | |
# Login to Amazon ECR Public | |
- name: Login to Amazon ECR Public | |
id: login-ecr-public | |
uses: aws-actions/amazon-ecr-login@v1 | |
with: | |
registry-type: public | |
# Download Artifact | |
- name: Download Artifact | |
uses: actions/download-artifact@v3 | |
with: | |
name: ${{ env.ARTIFACT_NAME }} | |
path: . | |
# Docker build & push to AWS ECR Public | |
- name: Docker build & push | |
run: | | |
docker build \ | |
--build-arg JAR_FILENAME=spring/target/${{ env.JAR_FILENAME }}.jar \ | |
-t ${{ vars.AWS_ECR_URI }}/${{ vars.AWS_ECR_REPOSITORY_NAME }}:latest \ | |
-t ${{ vars.AWS_ECR_URI }}/${{ vars.AWS_ECR_REPOSITORY_NAME }}:${{ github.sha }} \ | |
-f docker/Dockerfile \ | |
. | |
docker push ${{ vars.AWS_ECR_URI }}/${{ vars.AWS_ECR_REPOSITORY_NAME }} --all-tags | |
deploy: | |
name: Deploy to AWS EC2 | |
needs: docker-push | |
runs-on: ubuntu-latest | |
environment: production | |
if: github.event_name == 'push' && github.ref_name == 'main' | |
steps: | |
# Restart systemd service | |
- name: Run Application | |
uses: appleboy/[email protected] | |
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 ${{ env.SYSTEMD_SERVICE_NAME }} | |