Skip to content

Update prod-apigateway-deploy.yml #18

Update prod-apigateway-deploy.yml

Update prod-apigateway-deploy.yml #18

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle
name: APIGateway-Service
on:
push:
branches: [ "prod-apigateway" ]
pull_request:
branches: [ "prod-apigateway" ]
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Clean Gradle Cache
run: |
cd BE-APIGateway-Server
ls
./gradlew clean
- name: Make application.yml
run: |
mkdir -p src/main/resources
echo "$APPLICATION_APIGATEWAY" > src/main/resources/application.yml
env:
APPLICATION: ${{ secrets.APPLICATION_APIGATEWAY }}
- name: Grant execute permission for gradlew
run: |
cd BE-APIGateway-Server
ls
chmod +x gradlew
- name: Build with Gradle
run: |
cd BE-APIGateway-Server
ls
./gradlew build -x test
- name: Docker build
run: |
cd BE-APIGateway-Server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t app .
docker tag app ${{ secrets.DOCKER_USERNAME }}/apigateway:latest
docker push ${{ secrets.DOCKER_USERNAME }}/apigateway:latest
- name: Stop and Remove existing Docker containers
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD_1 }}
username: ec2-user
key: ${{ secrets.PRIVATE_KEY_1 }}
script: |
cd ./BE-APIGateway-Server
docker-compose -f docker-compose-gateway.yml down
- name: docker-compose.yml
uses: appleboy/scp-action@master
with:
username: ec2-user
host: ${{ secrets.HOST_PROD_1 }}
key: ${{ secrets.PRIVATE_KEY_1 }}
port: ${{ secrets.PORT }}
source: "./BE-APIGateway-Server/docker-compose-gateway.yml"
target: "/home/ec2-user/"
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD_1 }}
username: ec2-user
key: ${{ secrets.PRIVATE_KEY_1 }}
script: |
docker pull ${{ secrets.DOCKER_USERNAME }}/apigateway:latest
docker image prune -a -f
cd ./BE-APIGateway-Server
docker-compose -f docker-compose-gateway.yml up -d