Skip to content

Update Dockerfile

Update Dockerfile #54

Workflow file for this run

name: CI/CD using github actions & docker
on:
push:
branches: [ "main" ]
jobs:
CI-CD:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v2
with:
java-version: '17'
distribution: 'temurin'
- name: make application.yml
run: |
cd ./src/main/resources
touch ./application.yml
echo "${{ secrets.APPLICATION }}" > ./application.yml
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: set chmod
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Docker build
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -t alimo . # Dockerfile 경로 수정
docker tag alimo ${{ secrets.DOCKER_USERNAME }}/alimo:latest
docker push ${{ secrets.DOCKER_USERNAME }}/alimo:latest
- name: Deploy with SSH
if: github.ref == 'refs/heads/main'
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }} # EC2 인스턴스 퍼블릭 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # pem 키
port: ${{ secrets.PORT }} # ssh port (22)
envs: GITHUB_SHA
script: |
docker stop sopo_v2 || true
docker rm sopo_v2 || true
docker rmi ${{ secrets.DOCKER_USERNAME }}/sopo_v2 || true
docker pull ${{ secrets.DOCKER_USERNAME }}/sopo_v2
docker run -d -p 8080:8080 --name sopo_v2 ${{ secrets.DOCKER_USERNAME }}/sopo_v2
sudo chkconfig --add redis-server
sudo chkconfig --level 345 redis-server on
sudo service reids-server start
mkdir -p /home/ubuntu/app
cd /home/ubuntu/app
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
# Docker Compose 명령어 실행
docker-compose pull
docker-compose up -d
docker system prune -f