Skip to content

Feat: Deploy docker-compose for develop branch to test server #1

Feat: Deploy docker-compose for develop branch to test server

Feat: Deploy docker-compose for develop branch to test server #1

Workflow file for this run

name: Build And Deploy for develop branch to test server
on:
push:
branches: [ "develop" ]
permissions:
contents: read
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: "adopt"
- name: Make folder resources
run: |
cd ./server/src/main
mkdir resources
cd resources
- name: Make application.properties
run: |
cd ./server/src/main/resources
touch ./application.properties
echo "${{ secrets.PROPERTIES }}" > ./application.properties
- name: Build with Gradle
run: |
cd server
chmod +x ./gradlew
./gradlew clean build -x test
- name: Docker build & push to docker repo
run: |
cd server
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }}:latest .
docker push ${{ secrets.DOCKER_REPO }}:latest
pull-and-deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Remove & Change Docker-compose
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
if [ -f docker-compose.yml ]; then
sudo rm docker-compose.yml
fi
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
- name: Pull Server Docker image
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo docker rm -f $(docker ps -qa)
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
- name: Install Docker-compose & Execute
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.TEST_EC2_PUBLIC_IP }}
username: ubuntu
key: ${{ secrets.TEST_SSH_PRIVATE_KEY }}
envs: GITHUB_SHA
script: |
sudo apt-get update
sudo apt-get install -y docker-compose
sudo docker-compose up