From 262d3938c3350258fd631d4c5d5e98be5c5997f8 Mon Sep 17 00:00:00 2001 From: Miensoap Date: Fri, 24 May 2024 13:25:18 +0900 Subject: [PATCH] Create Jenkinsfile Update deploy.yml Update Jenkinsfile Update Jenkinsfile Update Jenkinsfile Update Jenkinsfile Update deploy.yml Update Dockerfile --- .github/workflows/deploy.yml | 2 -- be/Jenkinsfile | 55 ++++++++++++++++++++++++++++++++++++ be/issue_tracker/Dockerfile | 4 +-- 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 be/Jenkinsfile diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index e1ac28588..187777a73 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -3,8 +3,6 @@ name: CD with Gradle on: push: branches: [ "Deploy" ] - pull_request: - branches: [ "Deploy" ] permissions: contents: read diff --git a/be/Jenkinsfile b/be/Jenkinsfile new file mode 100644 index 000000000..d28b04b26 --- /dev/null +++ b/be/Jenkinsfile @@ -0,0 +1,55 @@ +pipeline { + agent any + + environment { + DOCKERHUB_CREDENTIALS = credentials('docker-hub-credentials') + DOCKER_IMAGE = 'miensoap/issue-tracker' + } + + stages { + + stage('github-clone') { + steps { + git branch: 'Deploy', + credentialsId: 'github-token', + url: 'https://github.com/codesquad-masters2024-team01/issue-tracker' + } + } + + stage('build-docker-image') { + steps { + script { + dir('be/issue_tracker') { + // Bash 사용하여 Docker 이미지 빌드 + sh 'docker build -t ${DOCKER_IMAGE}:${BUILD_ID} . ' + } + } + } + } + + stage('docker-login') { + steps { + script { + // Docker Hub 로그인 + sh "echo ${DOCKERHUB_CREDENTIALS_PSW} | docker login -u ${DOCKERHUB_CREDENTIALS_USR} --password-stdin" + } + } + } + + stage('push-docker-image') { + steps { + script { + // Docker 이미지 푸시 + sh 'docker push ${DOCKER_IMAGE}:${env.BUILD_ID}' + } + } + } + } + + post { + always { + // Clean up Docker images after the build + sh 'docker rmi ${DOCKER_IMAGE}:${env.BUILD_ID}' + } + } +} diff --git a/be/issue_tracker/Dockerfile b/be/issue_tracker/Dockerfile index 1c8c7b7b1..0a6991d80 100644 --- a/be/issue_tracker/Dockerfile +++ b/be/issue_tracker/Dockerfile @@ -9,5 +9,5 @@ ARG JAR_FILE=build/libs/*.jar COPY ${JAR_FILE} app.jar EXPOSE 8080 - -ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file +ENV TZ Asia/Seoul +ENTRYPOINT ["java","-jar","/app.jar"]