Skip to content

Feat: nginx, https 배포 #113

Feat: nginx, https 배포

Feat: nginx, https 배포 #113

name: CI/CD using actions & docker
on:
push:
branches: ["main", "develop"]
pull_request:
branches: ["main", "develop"]
jobs:
build-docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: Grant execute permission to Gradle wrapper
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew bootJar
- name: create deploy directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
mkdir -p /home/ubuntu/deploy
- name: copy docker-compose.yml
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
source: "docker-compose.yml"
target: "/home/ubuntu/deploy/"
- name: Create custom Docker network
run: docker network create app-network
- name: Docker build and push
run: docker build -t yeoljeongping/reflogdocker .
- name: docker login
uses: docker/login-action@v2
with:
username: ${{secrets.DOCKER_USERNAME}}
password: ${{secrets.DOCKER_PASSWORD}}
- name: docker Hub push
run: docker push yeoljeongping/reflogdocker
deploy:
needs: build-docker-image
runs-on: ubuntu-latest
steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST_PROD }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
port: 22
script: |
echo "DB_URL=${{ secrets.DB_URL }}" >> ~/deploy/.env
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> ~/deploy/.env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> ~/deploy/.env
echo "KAKAO_CLIENT_ID=${{ secrets.KAKAO_CLIENT_ID }}" >> ~/deploy/.env
echo "KAKAO_CLIENT_SECRET=${{ secrets.KAKAO_CLIENT_SECRET }}" >> ~/deploy/.env
echo "NAVER_CLIENT_ID=${{ secrets.NAVER_CLIENT_ID }}" >> ~/deploy/.env
echo "NAVER_CLIENT_SECRET=${{ secrets.NAVER_CLIENT_SECRET }}" >> ~/deploy/.env
echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> ~/deploy/.env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> ~/deploy/.env
echo "AWS_ACCESSKEY=${{ secrets.AWS_ACCESSKEY }}" >> ~/deploy/.env
echo "AWS_BUCKET=${{ secrets.AWS_BUCKET }}" >> ~/deploy/.env
echo "AWS_SECRETKEY=${{ secrets.AWS_SECRETKEY }}" >> ~/deploy/.env
echo "MAIL_USERNAME=${{ secrets.MAIL_USERNAME }}" >> ~/deploy/.env
echo "MAIL_PASSWORD=${{ secrets.MAIL_PASSWORD }}" >> ~/deploy/.env
sudo docker-compose -f ~/deploy/docker-compose.yml pull
sudo docker-compose -f ~/deploy/docker-compose.yml up -d
sudo docker image prune -f