Skip to content

Update docker-compose.yml for nginx #152

Update docker-compose.yml for nginx

Update docker-compose.yml for nginx #152

Workflow file for this run

name: Build and Deploy to AWS
on: [ push, workflow_dispatch ]
env:
JAR_FILENAME: LegendsOfTheThreeKingdoms
ARTIFACT_NAME: backend-app
SYSTEMD_SERVICE_NAME: ThreeKingdoms
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'
# List Pom.xml
- name: List LegendsOfTheThreeKingdoms Files
run: ls
# Get Path
- name: Get Path
run: pwd
# Maven Verify
- name: Maven Verify
run: mvn -f LegendsOfTheThreeKingdoms/pom.xml -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
- name: List LegendsOfTheThreeKingdoms
run: ls LegendsOfTheThreeKingdoms/spring/target
# 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: |
LegendsOfTheThreeKingdoms/spring/target/spring-*.jar
LegendsOfTheThreeKingdoms/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:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
# Login to Amazon ECR Public
- name: Login to Amazon ECR Public
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
# Download Artifact
- name: Download Artifact
uses: actions/download-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: .
- name: List All Target File
run: ls
- name: Get Path
run: pwd
# Docker build & push to AWS ECR Public
- name: Docker build & push
run: |
docker build \
--build-arg JAR_FILENAME=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/ssh-action@v0.1.10
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
port: 22
key: ${{ secrets.EC2_KEY }}
script: |
uname -a
whoami
pwd
sudo systemctl restart ${{ env.SYSTEMD_SERVICE_NAME }}