Skip to content

Fix: develop.yml add user #11

Fix: develop.yml add user

Fix: develop.yml add user #11

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_DEVELOP }}" > ./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: Install Curl
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 ! command -v curl &> /dev/null; then
sudo apt-get update
sudo apt-get install -y curl
fi
- name: Install Docker
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 ! command -v docker &> /dev/null; then
sudo apt-get update
curl -fsSL https://download.docker.com/linux/static/stable/x86_64/docker-20.10.22.tgz -o docker-20.10.22.tgz
tar xzvf docker-20.10.22.tgz
sudo systemctl start docker
sudo systemctl enable docker
fi
- name: Install 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 ! command -v docker-compose &> /dev/null; then
sudo curl -L "https://github.com/docker/compose/releases/download/v2.15.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
else
echo "Docker Compose already installed via curl."
fi
- name: Remove & Change docker-compose file
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
curl -o docker-compose.yml -L https://raw.githubusercontent.com/kookmin-sw/capstone-2024-14/develop/server/docker-compose.yml
cat docker-compose.yml
- name: Remove & Change 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 usermod -aG docker $USER
if [ -n "$(docker ps -qa)" ]; then
sudo docker rm -f $(docker ps -qa)
fi
sudo docker pull ${{ secrets.DOCKER_REPO }}:latest
sudo docker image prune -f
- name: 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 docker-compose up