Skip to content

Merge pull request #26 from lemoncloud-capstone/BE_day #36

Merge pull request #26 from lemoncloud-capstone/BE_day

Merge pull request #26 from lemoncloud-capstone/BE_day #36

Workflow file for this run

name: dev_deploy
on:
push:
branches: [develop]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Node.js and npm
uses: actions/setup-node@v2
with:
node-version: '20'
cache: 'npm'
- name: npm install
run: |
npm install --legacy-peer-deps
- name: Build apps
run: |
npm run build:web
npm run build:server
- name: Create .env file
run: |
echo "DOCKERHUB_USERNAME=${{ secrets.DOCKERHUB_USERNAME }}" > .env
echo "KAKAO_REST_API_KEY=${{ secrets.KAKAO_REST_API_KEY }}" >> .env
echo "KAKAO_REDIRECT_URI=${{ secrets.KAKAO_REDIRECT_URI }}" >> .env
echo "TOKEN_SECRET=${{ secrets.TOKEN_SECRET }}" >> .env
echo "ACCESS_KEY_ID=${{ secrets.ACCESS_KEY_ID }}" >> .env
echo "SECRET_ACCESS_KEY=${{ secrets.SECRET_ACCESS_KEY }}" >> .env
echo "REGION=${{ secrets.REGION }}" >> .env
echo "LOCAL_ENDPOINT=${{ secrets.LOCAL_ENDPOINT }}" >> .env
echo "BUCKET_NAME=${{secrets.BUCKET_NAME}}" >> .env
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker image
run: |
docker-compose up -d --build
- name: Push Docker Image to Docker hub
run: |
docker push ${{ secrets.DOCKERHUB_USERNAME }}/web
docker push ${{ secrets.DOCKERHUB_USERNAME }}/server
docker push ${{ secrets.DOCKERHUB_USERNAME }}/nginx
- name: Copy docker-compose.yml to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }} # aws ip 주소
username: ${{ secrets.EC2_USERNAME }} # ec2 접속 유저네임
key: ${{ secrets.KEY }} # ssh 공개키
port: 22
source: './docker-compose.yml,./.env'
target: './'
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.KEY }}
port: 22
script: |
sudo docker-compose down
sudo docker-compose pull
sudo docker-compose up -d
sudo docker image prune -f