config: docker 등 빌드 소스정리

main
minuk926 2 years ago
parent 57bb57f1a8
commit 393a27fc4b

@ -1,22 +0,0 @@
node_modules
npm-debug.log
# .git 과 .cache 폴더를 무시
.git
.cache
# ignore all *.class files in all folders, including build root
# 모든 폴더안에 있는 모든, *.class 파일들을 무시
**/*.class
# 모든 마크다운 파일들 (md) 파일들을 무시,
# 모든 README*.md 파일 무시
*.md
IREADME*.md
.gradle
build
.idea
out
work
data

@ -1,74 +0,0 @@
name: Deploy to Amazon EC2(github -> package -> EC2 docker image)
on:
push:
branches: [ master ] # push할 때 동작할 branch를 입력해주세요.
workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'debug'
tags:
description: 'Run action'
required: true
default: 'Run '
env:
#DOCKER_IMAGE: ghcr.io/{Repository author}/{Repository name} # 예를 들면, ghcr.io/dolphago/github-follow-unfollow
DOCKER_IMAGE: ghcr.io/${{ github.actor }}/xit-framework
VERSION: ${{ github.sha }}
NAME: xit-framework-bo
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Check out source code
uses: actions/checkout@v2
- name: Set up docker buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Cache docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.VERSION }} # runner 설정에서 읽어들일거에요.
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GIT_ACS_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
builder: ${{ steps.buildx.outputs.name }}
push: true #${{ github.event_name != 'pull_request' }}
tags: ${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
deploy:
needs: build
name: Deploy
runs-on: [ self-hosted, label-development ]
steps:
- name: Login to ghcr
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GIT_ACS_TOKEN }}
- name: Docker run
#docker ps -q --filter "name=xit-framework-bo" | grep -q . && docker stop xit-framework-bo && docker rm -fv xit-framework-bo
#docker run -d -p 8090:8090 --name xit-framework-bo --restart always ${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
#docker run -d -p 8090:8090 --name xit-framework-bo --restart always ${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
#docker ps -q --filter "name=xit-framework-bo" | grep -q . && docker stop xit-framework-bo && docker rm -fv xit-framework-bo
#docker stop ${{ env.NAME }} && docker rm ${{ env.NAME }} && docker rmi ${{ env.DOCKER_IMAGE }}:latest
run: |
docker run -d -p 8090:8090 --name ${{ env.NAME }} --restart always ${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
sleep 5
docker image prune -a
sleep 5

@ -1,46 +0,0 @@
FROM gradle:7-jdk8 AS build
WORKDIR /application
COPY --chown=gradle:gradle ./ ./
#COPY ./ ./
#RUN chmod +x ./gradlew
RUN gradle clean bootWar
FROM openjdk:8-jre-slim
WORKDIR /app
COPY --from=build /application/build/libs/*.war ./ROOT.war
EXPOSE 8090
#ENTRYPOINT ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Dspring.profiles.active=dev","-jar"," /app/ROOT.war"]
ENTRYPOINT ["java", "-jar", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Dspring.profiles.active=dev", "/app/ROOT.war"]
#ENTRYPOINT ["java", "-Dspring.profiles.active=dev", "-jar", "/application/build/libs/core-0.0.1-SNAPSHOT.war"]
#FROM openjdk:8-jdk-alpine as builder
#WORKDIR application
#COPY ./ ./
#RUN chmod +x ./gradlew
##--args='--spring.profiles.active=dev'
#RUN ./gradlew clean bootWar
##CMD["./gradlew", "-Dspring.profiles.active=local", "clean", "bootWar"]
#
#EXPOSE 8090 8443
#ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=dev", "/application/build/libs/core-0.0.1-SNAPSHOT.war"]
#FROM postgres
#FROM tomcat:9.0
#ENV TZ="Asia/Seoul"
#RUN ln -fns /usr/share/zoneinfo/$TZ /etc/localtime
#RUN echo $TZ > /etc/timezone
#CMD ["/usr/local/tomcat/bin/catalina.sh", "stop"]
#CMD sleep 3
#
#RUN rm -rf /usr/local/tomcat/webapps/ROOT
#COPY --from=builder /application/build/libs/core-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war
#EXPOSE 8090 8443
#CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]
#FROM tomcat:9.0
#ENV TZ="Asia/Seoul"
#RUN ln -fns /usr/share/zoneinfo/$TZ /etc/localtime
#RUN echo $TZ > /etc/timezone
##RUN rm -rf /usr/local/tomcat/webapps/ROOT
#COPY repo/target/kuaa-management.war /usr/local/tomcat/webapps/ROOT.war
#EXPOSE 8009 8080 8443

148
Jenkinsfile vendored

@ -1,148 +0,0 @@
pipeline {
agent any
stages {
stage('Git Pull') {
steps {
script {
try {
//echo 'prepare'
//git branch: "master", credentialsId: "$GIT_CREDENTIALS_ID", url: 'git@github.com:minuk926/xit-framework.git/'
git branch: 'master', url: 'git@github.com:minuk926/xit-framework.git', credentialsId: 'jenkins_aws_connect_key'
sh rm -rf .git
sh 'ls -al'
env.cloneResult=true
} catch (error) {
print(error)
env.cloneResult=false
currentBuild.result = 'FAILURE'
}
}
}
}
stage('Build WAR') {
when {
expression {
return env.cloneResult ==~ /(?i)(Y|YES|T|TRUE|ON|RUN)/
}
}
steps {
script{
try {
sh """
rm -rf deploy
mkdir deploy
"""
sh "sudo sed -i \"s/module_name=.*/module_name=${env.JOB_NAME}\\:${env.BUILD_NUMBER}/g\" /var/lib/jenkins/workspace/${env.JOB_NAME}/src/main/resources/application.properties"
sh "cat /var/lib/jenkins/workspace/${env.JOB_NAME}/src/main/resources/application.properties"
sh 'gradlew clean bootWar'
sh """
cd deploy
cp /var/lib/jenkins/workspace/${env.JOB_NAME}/build/libs/*.war ./ROOT.war
"""
env.gradleBuildResult=true
} catch (error) {
print(error)
echo 'Remove Deploy Files'
sh "sudo rm -rf /var/lib/jenkins/workspace/${env.JOB_NAME}/*"
env.gradleBuildResult=false
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
slackSend channel: '#pipeline-deploy', color: 'good', message: "The pipeline ${currentBuild.fullDisplayName} stage Build WAR successfully."
}
failure {
slackSend channel: '#pipeline-deploy', color: 'danger', message: "The pipeline ${currentBuild.fullDisplayName} stage Build WAR failed."
}
}
}
stage('Docker Build'){
when {
expression {
return env.mavenBuildResult ==~ /(?i)(Y|YES|T|TRUE|ON|RUN)/
}
}
steps {
script{
try {
sh"""
#!/bin/bash
cd ./deploy
cat>Dockerfile<<-EOF
FROM ${ECR_BASE_URL}:latest
ADD ${env.JOB_NAME}.jar /home/${env.JOB_NAME}.jar
CMD nohup java -jar /home/${env.JOB_NAME}.jar 1> /dev/null 2>&1
EXPOSE 9000
EOF"""
sh"""
cd ./deploy
docker rmi -f \$(docker images -q)
\$(aws ecr get-login --no-include-email --region ap-northeast-2)
docker build -t ${SERVICE_NAME.toLowerCase()} .
docker tag ${SERVICE_NAME.toLowerCase()}:latest ${ECR_TASK_URL}:ver${env.BUILD_NUMBER}
docker push ${ECR_TASK_URL}:ver${env.BUILD_NUMBER}
"""
echo 'Remove Deploy Files'
sh "sudo rm -rf /var/lib/jenkins/workspace/${env.JOB_NAME}/*"
env.dockerBuildResult=true
} catch (error) {
print(error)
echo 'Remove Deploy Files'
sh "sudo rm -rf /var/lib/jenkins/workspace/${env.JOB_NAME}/*"
env.dockerBuildResult=false
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
slackSend channel: '#jenkins', color: 'good', message: "The pipeline ${currentBuild.fullDisplayName} stage Docker Build successfully."
}
failure {
slackSend channel: '#jenkins', color: 'danger', message: "The pipeline ${currentBuild.fullDisplayName} stage Docker Build failed."
}
}
}
stage('Deploy'){
when {
expression {
return env.dockerBuildResult ==~ /(?i)(Y|YES|T|TRUE|ON|RUN)/
}
}
steps {
script{
try {
withAWS(credentials:"$AWS_CREDENTIALS") {
sh "aws ecs describe-task-definition --task-definition ${TASK_DEFINITION} --region ap-northeast-2 --query \"taskDefinition.{\"family\": family, \"containerDefinitions\": containerDefinitions, \"executionRoleArn\": executionRoleArn,\"requiresCompatibilities\": requiresCompatibilities}\" --output json > task-definition.json"
def task_repository_name = sh(
script:"""
echo \"${ECR_TASK_URL}\" | awk \'{ split(\$0, arr, \"/\"); print arr[2] }\'
""",
returnStdout: true
).trim()
sh "sudo sed -i \"9s/${task_repository_name}:.*/${task_repository_name}:ver${env.BUILD_NUMBER}\\\",/g\" task-definition.json"
sh "cat task-definition.json"
sh "aws ecs register-task-definition --cli-input-json file://task-definition.json --region ap-northeast-2"
sh "aws ecs update-service --cluster ${CLUSTER_NAME} --service ${SERVICE_NAME} --task-definition ${TASK_DEFINITION} --region ap-northeast-2"
}
} catch (error) {
print(error)
echo 'Remove Deploy Files'
sh "sudo rm -rf /var/lib/jenkins/workspace/${env.JOB_NAME}/*"
currentBuild.result = 'FAILURE'
}
}
}
post {
success {
slackSend channel: '#jenkins', color: 'good', message: "The pipeline ${currentBuild.fullDisplayName} successfully."
}
failure {
slackSend channel: '#jenkins', color: 'danger', message: "The pipeline ${currentBuild.fullDisplayName} failed."
}
}
}
}
}

@ -1,26 +0,0 @@
version: 0.0
os: linux
files:
- source: /
destination: /home/ubuntu/admin/bo # 배포 파일 도착 폴더
overwrite: yes # 안돼면, 아래 hooks BeforeInstall 추가, 파일 삭제
permissions:
- object: /
pattern: "**" # 모든 파일의 권한 설정
owner: ubuntu
group: ubuntu
# mode: 755
hooks:
# BeforeInstall: "BeforeInstallHookFunctionName"
# AfterInstall: "AfterInstallHookFunctionName"
# ApplicationStop:
# - timeout: 2
ApplicationStart: # 파일이 도착 후 실행
- location: deploy.sh
timeout: 60 # 60 안에 실행, 60 뒤엔 배포 실패로 변경
runas: ubuntu
# ValidateService: # deplo 실행 후, 빌드파일이 배포가 되었다면, 서버체크
# - location: server-check.sh
# timeout: 60

@ -1,25 +0,0 @@
#!/usr/bin/env bash
REPOSITORY=/home/ubuntu/xit-framework/bo
cd $REPOSITORY
APP_NAME=xit-framework-bo
WAR_NAME=$(ls $REPOSITORY | grep '.war' | tail -n 1)
WAR_PATH=$REPOSITORY/$WAR_NAME
echo "> war 파일명: $WAR_NAME" >> /home/ubuntu/xit-framework/bo/deploy.log
echo "> war 파일명: $WAR_PATH" >> /home/ubuntu/xit-framework/bo/deploy.log
CURRENT_PID=$(pgrep -f $APP_NAME)
echo "> CURRENT_PID : $CURRENT_PID" >> /home/ubuntu/xit-framework/bo/deploy.log
if [ -z $CURRENT_PID ]
then
echo "> 종료할것 없음."
else
echo "> kill -9 $CURRENT_PID"
kill -9 $CURRENT_PID
sleep 5
fi
rm -rf work/
echo "> $WAR_PATH 배포"
nohup java -jar -Dspring.profiles.active=local $WAR_PATH > /dev/null 2> /dev/null < /dev/null &

@ -1,27 +0,0 @@
version: "3"
services:
backend:
build:
context: .
dockerfile: Dockerfile
ports:
- "8090:8090"
stdin_open: true
# volumes:
# - /app/node_modules
# - ./backend:/app
# environment:
# MYSQL_HOST: mysql
# MYSQL_USER: root
# MYSQL_ROOT_PASSWORD: johnahn777
# MYSQL_DATABASE: myapp
# MYSQL_PORT: 3306
#
#
# nginx:
# restart: always
# build:
# dockerfile: ../Dockerfile
# context: ./nginx
# ports:
# - "3000:80"
Loading…
Cancel
Save