Skip to content

Commit

Permalink
aws 자동배포 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
eun-hak committed Jul 1, 2024
1 parent 9f53a2b commit 2350576
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 11 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/cd-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Deploy to Docker Hub and EC2

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Login to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker image
uses: docker/build-push-action@v2
with:
context: .
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/nextjs-app:latest

- name: Logout from Docker Hub
run: docker logout

deploy:
runs-on: ubuntu-latest
needs: build

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install SSH key
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}

- name: Deploy to EC2
run: |
ssh -o StrictHostKeyChecking=no ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF'
# Pull the latest Docker image
docker pull ${{ secrets.DOCKER_USERNAME }}/nextjs-app:latest
# Stop the currently running container
docker stop nextjs-app || true
# Remove the stopped container
docker rm nextjs-app || true
# Run the new container
docker run -d -p 3000:3000 --name nextjs-app ${{ secrets.DOCKER_USERNAME }}/nextjs-app:latest
# Restart PM2 to apply the new Docker container
pm2 restart all
EOF
25 changes: 14 additions & 11 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>수위키 ADMIN</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

<head>
<meta charset="UTF-8" />
<link rel="icon" href="/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>수위키 ADMIN2</title>
</head>

<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>

</html>

0 comments on commit 2350576

Please sign in to comment.