Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #341 from andresmoschini/DM-802-new-docker-registry
Browse files Browse the repository at this point in the history
DM-802 - New docker registry
  • Loading branch information
andresmoschini authored Dec 28, 2020
2 parents 7544ea7 + 59fb153 commit 76214a8
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 56 deletions.
159 changes: 115 additions & 44 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,126 @@ pipeline {
sh 'docker build --target build -f Dockerfile.swarm .'
}
}
stage('Publish pre-release images from pull request') {
when {
changeRequest target: 'master'
stage('Publish in fromdoppler') {
environment {
DOCKER_CREDENTIALS_ID = "dockerhub_fromdoppler"
DOCKER_IMAGE_NAME = "fromdoppler/doppler-for-shopify"
}
steps {
sh 'sh build-n-publish.sh --commit=${GIT_COMMIT} --name=pr-${CHANGE_ID}'
}
}
stage('Publish pre-release images from master') {
when {
branch 'master'
}
steps {
sh 'sh build-n-publish.sh --commit=${GIT_COMMIT} --name=master'
}
}
stage('Publish pre-release images from INT') {
when {
branch 'INT'
}
steps {
sh 'sh build-n-publish.sh --commit=${GIT_COMMIT} --name=INT'
}
}
stage('Publish pre-release images from PROD') {
// Temporal build for testing easily in production
when {
branch 'PROD'
}
steps {
sh 'sh build-n-publish.sh --commit=${GIT_COMMIT} --name=PROD'
}
}
stage('Publish final version images') {
when {
expression {
return isVersionTag(readCurrentTag())
stages {
stage('Publish pre-release images from pull request') {
when {
changeRequest target: 'master'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=pr-${CHANGE_ID}'
}
}
}
stage('Publish pre-release images from master') {
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=master'
}
}
}
stage('Publish pre-release images from INT') {
when {
branch 'INT'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=INT'
}
}
}
stage('Publish pre-release images from PROD') {
// Temporal build for testing easily in production
when {
branch 'PROD'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=PROD'
}
}
}
stage('Publish final version images') {
when {
expression {
return isVersionTag(readCurrentTag())
}
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --version=${TAG_NAME}'
}
}
}
}
steps {
sh 'sh build-n-publish.sh --commit=${GIT_COMMIT} --version=${TAG_NAME}'
}
}
stage('Generate version') {
when {
branch 'master'
stage('Publish in dopplerdock') {
environment {
DOCKER_CREDENTIALS_ID = "dockerhub_dopplerdock"
DOCKER_IMAGE_NAME = "dopplerdock/doppler-for-shopify"
}
steps {
sh 'echo "TODO: generate a tag automatically"'
stages {
stage('Publish pre-release images from pull request') {
when {
changeRequest target: 'master'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=pr-${CHANGE_ID}'
}
}
}
stage('Publish pre-release images from master') {
when {
branch 'master'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=master'
}
}
}
stage('Publish pre-release images from INT') {
when {
branch 'INT'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=INT'
}
}
}
stage('Publish pre-release images from PROD') {
// Temporal build for testing easily in production
when {
branch 'PROD'
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --name=PROD'
}
}
}
stage('Publish final version images') {
when {
expression {
return isVersionTag(readCurrentTag())
}
}
steps {
withDockerRegistry(credentialsId: "${DOCKER_CREDENTIALS_ID}", url: "") {
sh 'sh build-n-publish.sh --image=${DOCKER_IMAGE_NAME} --commit=${GIT_COMMIT} --version=${TAG_NAME}'
}
}
}
}
}
}
Expand Down
31 changes: 19 additions & 12 deletions build-n-publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ commit=""
name=""
version=""
versionPre=""
imageName=""

print_help () {
echo ""
Expand All @@ -12,23 +13,27 @@ print_help () {
echo "Build project's docker images and publish them to DockerHub"
echo ""
echo "Options:"
echo " -i, --image, image name (mandatory)"
echo " -c, --commit (mandatory)"
echo " -n, --name"
echo " -v, --version"
echo " -n, --name, version name"
echo " -v, --version, version number"
echo " -s, --pre-version-suffix (optional, only with version)"
echo " -h, --help"
echo "Only one of name or version parameters is required, and cannot be included together."
echo
echo "Examples:"
echo " sh build-n-publish.sh --commit=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 --version=v1.2.11"
echo " sh build-n-publish.sh --commit=e247ba0527665eb9dd7ffbff00bb42e5073cd457 --version=v0.0.0 --pre-version-suffix=commit-e247ba0527665eb9dd7ffbff00bb42e5073cd457"
echo " sh build-n-publish.sh -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5"
echo " sh build-n-publish.sh -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5 -s=beta1"
echo " sh build-n-publish.sh -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5 -s=pr123"
echo " sh build-n-publish.sh -image=fromdoppler/doppler-for-shopify --commit=aee25c286a7c8265e2b32ccc293f5ab0bd7a9d57 --version=v1.2.11"
echo " sh build-n-publish.sh -image=fromdoppler/doppler-for-shopify --commit=e247ba0527665eb9dd7ffbff00bb42e5073cd457 --version=v0.0.0 --pre-version-suffix=commit-e247ba0527665eb9dd7ffbff00bb42e5073cd457"
echo " sh build-n-publish.sh -i=fromdoppler/doppler-for-shopify -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5"
echo " sh build-n-publish.sh -i=fromdoppler/doppler-for-shopify -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5 -s=beta1"
echo " sh build-n-publish.sh -i=fromdoppler/doppler-for-shopify -c=94f85efb9c3689f409104ef7cde6813652ca59fb -v=v12.34.5 -s=pr123"
}

for i in "$@" ; do
case $i in
-i=*|--image=*)
imageName="${i#*=}"
;;
-c=*|--commit=*)
commit="${i#*=}"
;;
Expand All @@ -48,6 +53,13 @@ case $i in
esac
done

if [ -z "${imageName}" ]
then
echo "Error: image parameter is mandatory"
print_help
exit 1
fi

if [ -z "${commit}" ]
then
echo "Error: commit parameter is mandatory"
Expand Down Expand Up @@ -167,17 +179,12 @@ then
canonicalTag=${versionFull}
fi

imageName=fromdoppler/doppler-for-shopify

docker build \
-t "${imageName}:${canonicalTag}" \
--build-arg version="${versionFull}" \
-f Dockerfile.swarm \
.

# TODO: It could break concurrent deployments with different docker accounts
docker login -u="${DOCKER_WRITTER_USERNAME}" -p="${DOCKER_WRITTER_PASSWORD}"

if [ -n "${version}" ]
then
docker tag "${imageName}:${canonicalTag}" "${imageName}:${versionMayor}"
Expand Down

0 comments on commit 76214a8

Please sign in to comment.