Skip to content

Commit 88b6047

Browse files
szhGitHub Enterprise
authored and
GitHub Enterprise
committed
Merge pull request #6 from Conjur-Enterprise/use-release-stage
CNJR-5578: Use internal registry for pre-releases
2 parents ada6315 + 1453967 commit 88b6047

File tree

7 files changed

+221
-18
lines changed

7 files changed

+221
-18
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
.bundle/
22
rspec_junit.xml
3+
# Temporary directory to store the CyberArk proxy CA certificate
4+
build_ca_certificate/

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [1.3.3] - 2024-11-08
10+
### Changed
11+
- Decrease Docker image size by using ruby:3-alpine base image (CNJR-5578)
12+
913
## [1.3.2] - 2024-11-05
1014
### Changed
1115
- Use internal auto release process (CNJR-5578)

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
FROM ruby:3
1+
FROM ruby:3-alpine
2+
3+
# We use git in the Gemspec file
4+
RUN apk update && apk add --no-cache git
25

36
RUN gem install bundler --no-document
47

Jenkinsfile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ if (params.MODE == "PROMOTE") {
1717
// Any publishing of targetVersion artifacts occur here
1818
// Anything added to assetDirectory will be attached to the Github Release
1919

20-
infrapool.agentSh "./publish.sh v${targetVersion}"
20+
// Pull existing images from internal registry in order to promote
21+
infrapool.agentSh """
22+
docker pull registry.tld/parse-a-changelog:${sourceVersion}
23+
# Promote source version to target version.
24+
./publish.sh --promote --source ${sourceVersion} --target ${targetVersion}
25+
"""
2126

2227
// Ensure the working directory is a safe git directory for the subsequent
2328
// promotion operations after this block.
@@ -121,6 +126,15 @@ pipeline {
121126
}
122127
}
123128

129+
// Allows for the promotion of images.
130+
stage('Push images to internal registry') {
131+
steps {
132+
script {
133+
infrapool.agentSh './publish.sh --internal'
134+
}
135+
}
136+
}
137+
124138
stage('Release') {
125139
when {
126140
expression {
@@ -144,6 +158,7 @@ pipeline {
144158
If your assets are in target on the main Jenkins agent, use:
145159
infrapool.agentPut(from: 'target/', to: assetDirectory)
146160
*/
161+
infrapool.agentSh './publish.sh --edge'
147162
}
148163
}
149164
}

build.sh

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,22 @@
22

33
set -eux
44

5-
docker build . --tag parse-a-changelog
5+
. build_utils.sh
6+
7+
VERSION=unreleased
8+
# Version derived from CHANGELOG and automated release library
9+
[ -f VERSION ] && VERSION=$(<VERSION)
10+
FULL_VERSION_TAG="$VERSION-$(git_tag)"
11+
12+
function main() {
13+
retrieve_cyberark_ca_cert
14+
build_docker_image
15+
}
16+
17+
function build_docker_image() {
18+
docker build . \
19+
--tag parse-a-changelog:latest \
20+
--tag "parse-a-changelog:${FULL_VERSION_TAG}"
21+
}
22+
23+
main

build_utils.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
####
6+
# Functions to generate version numbers for this project
7+
####
8+
9+
git_tag() {
10+
git rev-parse --short HEAD
11+
}
12+
13+
# generate less specific versions, eg. given 1.2.3 will print 1.2 and 1
14+
# (note: the argument itself is not printed, append it explicitly if needed)
15+
gen_versions() {
16+
local version=$1
17+
while [[ $version = *.* ]]; do
18+
version=${version%.*}
19+
echo $version
20+
done
21+
}
22+
23+
function tag_and_push() {
24+
local source="$1"
25+
shift
26+
local target="$1"
27+
shift
28+
29+
docker tag "${source}" "${target}"
30+
docker push "${target}"
31+
}
32+
33+
function retrieve_cyberark_ca_cert() {
34+
# On CyberArk dev laptops, golang module dependencies are downloaded with a
35+
# corporate proxy in the middle. For these connections to succeed we need to
36+
# configure the proxy CA certificate in build containers.
37+
#
38+
# To allow this script to also work on non-CyberArk laptops where the CA
39+
# certificate is not available, we update container certificates based on
40+
# a (potentially empty) certificate directory, rather than relying on the
41+
# CA file itself.
42+
mkdir -p "$(repo_root)/build_ca_certificate"
43+
44+
# Only attempt to extract the certificate if the security
45+
# command is available.
46+
#
47+
# The certificate file must have the .crt extension to be imported
48+
# by `update-ca-certificates`.
49+
if command -v security &> /dev/null
50+
then
51+
security find-certificate \
52+
-a -c "CyberArk Root CA" \
53+
-p > build_ca_certificate/cyberark_root.crt
54+
fi
55+
}
56+
57+
repo_root() {
58+
git rev-parse --show-toplevel
59+
}

publish.sh

Lines changed: 117 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,126 @@
22

33
set -e
44

5-
# This script will publish to rubygems and dockerhub
5+
# The following is used to:
6+
# Publish images on pre-release and tag as edge
7+
# Promote pre-releases to releases and tag as latest
68

7-
# Clone the release-tools repository if it doesn't exist
8-
if [ ! -d release-tools ]; then
9-
git clone git@github.com:conjurinc/release-tools.git
9+
. build_utils.sh
10+
11+
function print_help() {
12+
echo "Build Usage: $0 --internal"
13+
echo "Release Usage: $0 --edge"
14+
echo "Promote Usage: $0 --promote --source <VERSION> --target <VERSION>"
15+
echo " --internal: publish images to registry.tld"
16+
echo " --edge: publish docker images to docker hub"
17+
echo " --source <VERSION>: specify version number of local image"
18+
echo " --target <VERSION>: specify version number of remote image"
19+
}
20+
21+
# Fail if no arguments are given.
22+
if [[ $# -lt 1 ]]; then
23+
print_help
24+
exit 1
1025
fi
1126

12-
export PATH=$PWD/release-tools/bin/:$PATH
27+
PUBLISH_INTERNAL=false
28+
PUBLISH_EDGE=false
29+
PROMOTE=false
1330

14-
# Build and publish rubygem
15-
summon --yaml "RUBYGEMS_API_KEY: !var rubygems/api-key" \
16-
publish-rubygem parse_a_changelog
31+
while [[ $# -gt 0 ]]; do
32+
case "$1" in
33+
--internal)
34+
PUBLISH_INTERNAL=true
35+
;;
36+
--edge)
37+
PUBLISH_EDGE=true
38+
;;
39+
--promote)
40+
PROMOTE=true
41+
;;
42+
--source)
43+
SOURCE_ARG="$2"
44+
shift
45+
;;
46+
--target)
47+
TARGET_ARG="$2"
48+
shift
49+
;;
50+
--help)
51+
print_help
52+
exit 1
53+
;;
54+
*)
55+
echo "Unknown option: ${1}"
56+
print_help
57+
exit 1
58+
;;
59+
esac
60+
shift
61+
done
1762

18-
# Publish to Docker Hub
19-
TAG_NAME=$1
20-
DOCKERHUB_IMAGE="cyberark/parse-a-changelog"
21-
docker tag parse-a-changelog "${DOCKERHUB_IMAGE}:latest"
22-
docker tag parse-a-changelog "${DOCKERHUB_IMAGE}:${TAG_NAME}"
63+
readonly IMAGE_NAME="parse-a-changelog"
64+
readonly REGISTRY='cyberark'
65+
readonly LOCAL_REGISTRY='registry.tld'
66+
# Version derived from CHANGLEOG and automated release library
67+
VERSION=$(<VERSION)
68+
readonly VERSION
69+
FULL_VERSION_TAG="$VERSION-$(git_tag)"
70+
readonly FULL_VERSION_TAG
2371

24-
docker push "${DOCKERHUB_IMAGE}:latest"
25-
docker push "${DOCKERHUB_IMAGE}:${TAG_NAME}"
72+
if [[ ${PUBLISH_INTERNAL} = true ]]; then
73+
echo "Publishing built images internally to registry.tld."
74+
SOURCE_TAG=$FULL_VERSION_TAG
75+
REMOTE_TAG=$VERSION
76+
77+
tag_and_push "${IMAGE_NAME}:${SOURCE_TAG}" "${LOCAL_REGISTRY}/${IMAGE_NAME}:${REMOTE_TAG}"
78+
fi
79+
80+
if [[ ${PUBLISH_EDGE} = true ]]; then
81+
echo "Performing edge release."
82+
SOURCE_TAG=$FULL_VERSION_TAG
83+
REMOTE_TAG=edge
84+
readonly TAGS=(
85+
"$VERSION"
86+
"$REMOTE_TAG"
87+
)
88+
89+
for tag in "${TAGS[@]}"; do
90+
tag_and_push "$IMAGE_NAME:$SOURCE_TAG" "$REGISTRY/$IMAGE_NAME:$tag"
91+
done
92+
fi
93+
94+
if [[ ${PROMOTE} = true ]]; then
95+
if [[ -z ${SOURCE_ARG:-} || -z ${TARGET_ARG:-} ]]; then
96+
echo "When promoting, --source and --target flags are required."
97+
print_help
98+
exit 1
99+
fi
100+
101+
# First publish the RubyGem
102+
echo "Publishing RubyGem"
103+
# Clone the release-tools repository if it doesn't exist
104+
if [ ! -d release-tools ]; then
105+
git clone git@github.com:conjurinc/release-tools.git
106+
fi
107+
export PATH=$PWD/release-tools/bin/:$PATH
108+
# Build and publish rubygem
109+
summon --yaml "RUBYGEMS_API_KEY: !var rubygems/api-key" \
110+
publish-rubygem parse_a_changelog
111+
112+
# Update vars to utilize build_utils
113+
SOURCE_TAG=$SOURCE_ARG
114+
REMOTE_TAG=$TARGET_ARG
115+
116+
echo "Promoting image to $REMOTE_TAG"
117+
readonly TAGS=(
118+
"$REMOTE_TAG"
119+
"latest"
120+
)
121+
122+
# Publish images to docker hub
123+
for tag in "${TAGS[@]}" $(gen_versions "$REMOTE_TAG"); do
124+
echo "Tagging and pushing $REGISTRY/$IMAGE_NAME:$tag"
125+
tag_and_push "${LOCAL_REGISTRY}/$IMAGE_NAME:$SOURCE_TAG" "$REGISTRY/$IMAGE_NAME:$tag"
126+
done
127+
fi

0 commit comments

Comments
 (0)