Skip to content

Commit

Permalink
Merge pull request #124 from LikeLion-at-DGU/develop
Browse files Browse the repository at this point in the history
Test
  • Loading branch information
sayyyho authored Oct 6, 2024
2 parents fd059be + 6ea0caa commit 44ada6f
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 21 deletions.
67 changes: 46 additions & 21 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
name: Deploy
name: Deploy to AWS EC2 using Docker

on:
push:
branches: ["main"]
branches:
- main

env:
DOCKER_IMAGE_NAME: ${{ secrets.DOCKER_IMAGE_NAME }}
EC2_HOST: ${{ secrets.EC2_HOST }}
EC2_SSH_USER: ${{ secrets.EC2_SSH_USER }}
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}

jobs:
build:
build-and-push-docker:
runs-on: ubuntu-latest
container:
image: pandoc/latex

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Create .env file
run: |
echo "VITE_BASE_URL=${{ secrets.VITE_BASE_URL }}" > .env
echo "VITE_GA_MEASUREMENT_ID=${{ secrets.VITE_GA_MEASUREMENT_ID }}" >> .env
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ env.DOCKER_IMAGE_NAME }}:latest

- name: creates output
run: sh ./build.sh
- name: Login to Docker Hub using Access Token
run: echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Pushes to origin repository
id: push_directory
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.AUTO_ACTIONS }}
- name: Push the Docker image
run: docker push ${{ env.DOCKER_IMAGE_NAME }}:latest

deploy-to-ec2:
needs: build-and-push-docker
runs-on: ubuntu-latest

steps:
- name: Deploy to EC2
uses: appleboy/ssh-action@master
with:
source-directory: "output"
destination-github-username: sayyyho
destination-repository-name: 2024_fall_festival_front
user-email: "[email protected]"
commit-message: "배포"

- name: Test get variable exported by push-to-another-repository
run: echo $DESTINATION_CLONED_DIRECTORY
host: ${{ env.EC2_HOST }}
username: ${{ env.EC2_SSH_USER }}
key: ${{ env.PRIVATE_KEY }}
script: |
CONTAINER_ID=$(sudo docker ps -aq --filter "name=kaboo-connection-container")
if [ ! -z "$CONTAINER_ID" ]; then
sudo docker stop $CONTAINER_ID || true
sudo docker rm -f $CONTAINER_ID || true
fi
sudo docker pull ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker run --name kaboo-connection-container -d -p 80:80 -p 3000:3000 -e TZ=Asia/Seoul ${{ env.DOCKER_IMAGE_NAME }}:latest
sudo docker image prune -f
40 changes: 40 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Base image with Node.js
FROM node:18-alpine as build

# Set working directory
WORKDIR /app

# Install dependencies
COPY package.json package-lock.json ./
RUN npm install

# Copy all files
COPY . .

# Build the application
RUN npm run build

# Production image for Nginx
FROM nginx:alpine

# Install Node.js in Nginx container
RUN apk add --no-cache nodejs npm

# Copy built application
COPY --from=build /app/dist /usr/share/nginx/html

# Copy Node.js server files
COPY --from=build /app/server.cjs /app/server.cjs
COPY --from=build /app/node_modules /app/node_modules

# Remove default nginx config
RUN rm /etc/nginx/conf.d/default.conf

# Copy custom nginx config
COPY ./nginx.conf /etc/nginx/conf.d

# Expose ports
EXPOSE 80 3000

# Run both Nginx and Node.js server
CMD ["sh", "-c", "node /app/server.cjs & nginx -g 'daemon off;'"]
11 changes: 11 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
server {
listen 80;
server_name dgu-booth.site;

location / {
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}

}

0 comments on commit 44ada6f

Please sign in to comment.