From ab2208430d812ccb2dd05b15907c47487dfe84be Mon Sep 17 00:00:00 2001 From: h-sooah Date: Wed, 24 Jan 2024 11:38:52 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20Github=20Actions=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 72 +++++++++++++++++++++++++----------- Dockerfile | 24 ++++++++++++ 2 files changed, 75 insertions(+), 21 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 19e2dd3..7e6f5c8 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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/ssh-action@v0.1.6 + 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 }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..7cbbad7 --- /dev/null +++ b/Dockerfile @@ -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"] +