Skip to content

Update Dockerfile

Update Dockerfile #41

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: set chmod
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: Build Docker image and push
run: |
docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/sopo_v2 .
docker push ${{ secrets.DOCKER_USERNAME }}/sopo_v2
- name: Deploy to Production
uses: appleboy/ssh-action@master
id: deploy-prod
with:
host: ${{ secrets.HOST_PROD }} # EC2 퍼블릭 IPv4 DNS
username: ubuntu
key: ${{ secrets.PRIVATE_KEY }} # EC2 private key
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
# Docker Compose 파일이 있는 디렉토리로 이동
mkdir -p /home/ubuntu/app
cd /home/ubuntu/app
# docker-compose.yml 파일을 생성하거나 덮어쓰기
echo "${{ secrets.DOCKER_COMPOSE }}" > docker-compose.yml
# Docker Compose 명령어 실행
docker-compose pull
docker-compose up -d
# 사용하지 않는 Docker 데이터 정리 (선택 사항)
docker system prune -f