Skip to content

Commit

Permalink
Merge pull request #11 from mobil2team/feat#9_deploy
Browse files Browse the repository at this point in the history
EC2 배포 & GitHub Actions
  • Loading branch information
Sang-minKIM authored Jan 24, 2024
2 parents 4241fca + ab22084 commit 5fc84d0
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 21 deletions.
72 changes: 51 additions & 21 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,59 @@ name: git push into another repo to deploy to vercel

on:
push:
branches: [main]
branches: [ "dev" ]
pull_request:
branches: [ "dev" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
container: pandoc/latex

steps:
- uses: actions/checkout@v2
- name: Install mustache (to update the date)
run: apk add ruby && gem install mustache
- name: creates output
run: sh ./build.sh
- name: Pushes to another repository
id: push_directory
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.AUTO_DEPLOY }}
with:
source-directory: 'output'
destination-github-username: Sang-minKIM
destination-repository-name: mobil2team-FE
user-email: ${{ secrets.OFFICIAL_ACCOUNT_EMAIL }}
commit-message: ${{ github.event.commits[0].message }}
target-branch: main
- name: Test get variable exported by push-to-another-repository
run: echo $DESTINATION_CLONED_DIRECTORY
- name: Checkout
uses: actions/checkout@v3

- name: Create secret file
run: |
touch ./.env
echo "${{ secrets.ENV}}" > ./.env
shell: bash

- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ secrets.DOCKER_REPO }}:latest

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_EC2_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_EC2_SECRET_ACCESS_KEY }}
aws-region: ap-northeast-2

- name: Deploy
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_SERVER_HOST }}
port: 22
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.PRIVATE_KEY }}
script: |
docker stop ${{ secrets.CONTAINER_NAME }}
docker rm ${{ secrets.CONTAINER_NAME }}
docker rmi $(docker images -q)
docker pull ${{ secrets.DOCKER_REPO }}
docker run -d -p 5173:5173 --name ${{ secrets.CONTAINER_NAME }} ${{ secrets.DOCKER_REPO }}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Use an official Node.js runtime as a base image
FROM node:21

# Set the working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the working directory
COPY package*.json ./

# Install app dependencies
RUN npm install

# Bundle app source
COPY . .

# Build TypeScript app
RUN npm run build

# Expose the port the app runs on
EXPOSE 5173

# Define the command to run your app
CMD ["npm", "run", "dev", "--", "--host"]

0 comments on commit 5fc84d0

Please sign in to comment.