Fix: develop.yml docker install chagne #15
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: 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 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 | |
sudo apt-get install \ | |
ca-certificates \ | |
curl \ | |
gnupg | |
sudo mkdir -m 0755 -p /etc/apt/keyrings | |
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg | |
echo \ | |
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ | |
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ | |
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | |
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
sudo docker run hello-world | |
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: | | |
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 | |