Skip to content

Commit

Permalink
infra: 배포 스크립트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
kyw0716 committed Oct 30, 2023
1 parent f765cf0 commit 8e928b1
Showing 1 changed file with 33 additions and 40 deletions.
73 changes: 33 additions & 40 deletions .github/workflows/frontend-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,48 @@ on:
- prod/frontend

jobs:
deploy:
runs-on: self-hosted
build:
runs-on: ubuntu-22.04
steps:
- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- uses: actions/checkout@v3
- name: Add Enviromnet
run: |
cd frontend
cd frontend
touch .env
echo "${{ secrets.GOOGLE_MAPS_API_KEY }}" >> .env
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: woowacarffeine/frontend
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
- name: Set up Node
uses: actions/setup-node@v3
with:
context: ./frontend
file: ./frontend/Dockerfile
push: true
tags: woowacarffeine/frontend:latest
labels: ${{ steps.meta.outputs.labels }}

- name: Join EC2 dev server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SERVER_KEY }}
port: ${{ secrets.SERVER_PORT }}
node-version: 18.16.0

script: |
sudo docker stop frontend || true
sudo docker container prune -f
- name: Install dependencies
run: npm install

sudo docker pull woowacarffeine/frontend:latest
- name: Cache node_modules
id: cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
sudo docker run -d -p 3000:80 \
--name frontend \
woowacarffeine/frontend:latest
- name: Build
run: npm run build

sudo docker image prune -a -f
- name: clean overlay
run: |
sudo docker image prune -f
sudo docker system prune -a -f
- name: Upload build files
uses: actions/upload-artifact@v3
with:
name: Prod
path: frontend/dist

deploy:
needs: build
runs-on: self-hosted
steps:
- name: Download the built file to AWS
uses: actions/download-artifact@v3
with:
name: Prod
path: frontend/prod/dist

0 comments on commit 8e928b1

Please sign in to comment.