-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from LikeLion-at-DGU/develop
Test
- Loading branch information
Showing
3 changed files
with
97 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;'"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |