Skip to content

Commit

Permalink
Merge pull request #31 from falconlee236/dev/ci-cd
Browse files Browse the repository at this point in the history
[DEV] 프로그램 배포 설정 및 code test용 github action 추가
  • Loading branch information
yymin1022 authored Nov 5, 2024
2 parents 76d37b5 + 438beb4 commit aa6e4e5
Show file tree
Hide file tree
Showing 6 changed files with 661 additions and 5 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/customCI.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: CI

on:
push:
branches: ['main']
pull_request:
branches: ['main']

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: npm package install
run: npm ci
- name: run eslint
run: npm run lint
- name: run build process
run: npm run build --if-present
- name: Analyze bundle sizes
uses: transferwise/actions-next-bundle-analyzer@v2
with:
comment-strategy: 'always'
- name: Delete merged branch
uses: SvanBoxel/delete-merged-branch@1.4.3
with:
delete_closed_pr: false
- name: Trigger Jenkins Multiple Jobs
uses: appleboy/jenkins-action@v0.0.2
with:
# jenkins base url
url: ${{secrets.JENKINS_URL}}
# jenkins username
user: sangylee
# jenkins api token
token: ${{secrets.JENKINS_API_TOKEN}}
# jenkins job
job: puang-web



16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# ./Dockerfile
FROM node:20-alpine3.19

WORKDIR /app

COPY . .

RUN npm ci

ENV PORT=3030

EXPOSE 3030

RUN npm run build

CMD [ "npm", "run", "start" ]
96 changes: 96 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
pipeline {
agent any

tools {nodejs "Node_version"}

environment {
DOCKER_COMPOSE_VERSION = '1.29.2'
AWS_PUBLIC_URL = "43.203.237.252"
DOCKERHUB_CREDENTIALS = credentials('dockerhub_token')
DOCKER_IMAGE = "falconlee236/puangfilm-web"
CONTAINER_NAME = "puangfilm-web"
DOCKERHUB_CREDENTIALS_PSW = credentials('DOCKERHUB_pwd')
DOCKERHUB_CREDENTIALS_USR = credentials('DOCKERHUB_id')
}

stages {

stage('github_clone') {
steps {
git branch: 'dev/ci-cd', credentialsId: 'github_token', url: 'https://github.com/falconlee236/PuangFilm-FE-local'
}
}

stage('env file copy') {
steps {
script {
sh "cp /var/jenkins_home/env/.env.local ."
}
}
}


stage('docker-build'){
steps {
script {
echo 'Build Docker'
sh 'docker build -t ${DOCKER_IMAGE} .'
}
}
}

stage('dockerhub-login') {
steps {
script {
sh 'echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin'
}
}
}

stage('Deploy image') {
steps {
script {
// 태그를 달아서 한 레포에 2개 이상 이미지를 배포할 수 있음
// sh 'docker image tag $DOCKER_REPO $DOCKER_REPO:$BUILD_NUMBER'
sh 'docker push $DOCKER_IMAGE'
}
}
}

stage('docker-image-pull') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker pull ${DOCKER_IMAGE}"'
}
}

}
}

stage('docker-clean-up') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker stop $CONTAINER_NAME"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker rm -f $CONTAINER_NAME"'
}
}

}
}

stage('docker-start') {
steps {
script {
sshagent(credentials: ['EC2_SSH']) {
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker run -p 3030:3030 --name $CONTAINER_NAME -d ${DOCKER_IMAGE}"'
sh 'ssh -o StrictHostKeyChecking=no ubuntu@${AWS_PUBLIC_URL} "docker image prune --force"'
}
}

}
}
}
}
Loading

0 comments on commit aa6e4e5

Please sign in to comment.