Merge branch 'main' into release #14
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: Release Deploy | |
on: | |
push: | |
branches: [ "release" ] | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '17' | |
distribution: 'corretto' | |
cache: "gradle" | |
- name: Build with Gradle | |
run: ./gradlew clean build --no-daemon --exclude-task test | |
- name: Login To DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_PASSWORD }} | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
push: true | |
build-args: | | |
DB_URL=${{ secrets.DB_URL }} | |
DB_USERNAME=${{ secrets.DB_USERNAME }} | |
DB_PASSWORD=${{ secrets.DB_PASSWORD }} | |
REDIS_URL=${{ secrets.REDIS_URL }} | |
tags: | | |
eatda/api-server:latest | |
- name: Get Github IP | |
id: ip | |
uses: haythem/[email protected] | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-region: ${{ secrets.AWS_REGION }} | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
- name: Add GitHub IP to AWS | |
run: | | |
aws ec2 authorize-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32 | |
- name: Deploy | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
key: ${{ secrets.EC2_SSH_KEY }} | |
username: ${{ secrets.EC2_USERNAME }} | |
port: ${{ secrets.EC2_SSH_PORT }} | |
timeout: 60s | |
script: | | |
cd eatda-api-server/ | |
sudo docker rm - f $(docker ps -qa) | |
sudo docker pull eatda/api-server:latest | |
sudo docker stop $(sudo docker ps -aq) | |
sudo docker run -p 8080:8080 -d eatda/api-server:latest --name api-server | |
- name: Remove IP FROM security group | |
run: | | |
aws ec2 revoke-security-group-ingress --group-id ${{ secrets.AWS_SG_ID }} --protocol tcp --port ${{ secrets.EC2_SSH_PORT }} --cidr ${{ steps.ip.outputs.ipv4 }}/32 |