docker buildx build --platform linux/amd64,linux/arm64 -t $imageName:$BUILD_NUMBER --push ."
로컬에서 생성한 docker image는 바로 사용가능하다.
jenkins에서 생성한 로컬 docker image는 서버로 이동 후 compose에서 pull 해서 사용할 수 없다.
→ Docker Hub가 있어야 한다…
environment { backImageName = "gogoadl247/spoparty-backend" frontImageName = "gogoadl247/spoparty-frontend" nginxImageName = "gogoadl247/spoparty-nginx" registryCredential = 'spoparty-docker' releaseServerAccount = 'ubuntu' releaseServerUri = 'i10a802.p.ssafy.io' }
stage('Image Build & DockerHub Push') {
steps {
dir('backend') {
script {
docker.withRegistry('', registryCredential) {
sh "docker buildx create --use --name spoparty-builder"
sh "docker buildx build --platform linux/amd64,linux/arm64 -t $backImageName:$BUILD_NUMBER --push ."
sh "docker buildx build --platform linux/amd64,linux/arm64 -t $backImageName:latest --push ."
}
}
}
}
}
stage('Before Service Stop') {
steps {
sshagent(credentials: ['ubuntu-a802']) {
sh '''
if test "ssh -o StrictHostKeyChecking=no $releaseServerAccount@$releaseServerUri "docker ps -aq --filter ancestor=$backImageName:latest"
"; then
ssh -o StrictHostKeyChecking=no $releaseServerAccount@$releaseServerUri "docker-compose down”
fi
'''
}
}
}
stage('DockerHub Pull') {
steps {
sshagent(credentials: ['ubuntu-a802']) {
sh "ssh -o StrictHostKeyChecking=no $releaseServerAccount@$releaseServerUri 'sudo docker pull $backImageName:latest'"
}
}
}
stage('Service Start') {
steps {
sshagent(credentials: ['ubuntu-a802']) {
sh '''
ssh -o StrictHostKeyChecking=no $releaseServerAccount@$releaseServerUri "sudo docker-compose up"
'''
}
}
}