Skip to content

Commit

Permalink
Seperated publish and build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
tedgin committed Jul 9, 2023
1 parent db20f30 commit 976070b
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 76 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ jobs:
run: ${{ github.repository }}/build

- name: build test image
# run: docker buildx build "${{ github.repository }}"/test
run: echo NOT IMPLEMENTED
run: docker buildx build "${{ github.repository }}"/test

- name: publish base image
if: ${{ github.ref_name == 'main' }}
# run: ${{ github.repository }}/build --push
run: echo NOT IMPLEMENTED
run: ${{ github.repository }}/publish
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get --quiet update && \
COPY apt.irods /etc/apt/preferences.d/irods
ADD https://packages.irods.org/irods-signing-key.asc /tmp/irods-signing-key.asc
RUN apt-get --quiet --yes install ca-certificates gnupg lsb-release && \
apt-key add /tmp/irods-signing-key.asc > 2>&1 && \
apt-key add /tmp/irods-signing-key.asc 2>&1 && \
echo deb [arch=amd64] https://packages.irods.org/apt/ "$(lsb_release --codename --short)" main \
> /etc/apt/sources.list.d/renci-irods.list && \
apt-get --quiet update && \
Expand Down
74 changes: 4 additions & 70 deletions build
Original file line number Diff line number Diff line change
Expand Up @@ -3,81 +3,15 @@
# Usage:
# build [options]
#
# This program builds the cyverse/irods image. Each build is tagged with the
# iRODS version and ISO 8601 style build time with the form `version_time`,
# e.g., `4.2.12_2023-06-18T12-32-00`.
#
# Options:
# -p, --push push the new image to Dockerhub
# This program builds the cyverse/irods image tagged with `new`.

set -o errexit -o nounset -o pipefail

EXEC_PATH="$(readlink --canonicalize "$0")"
readonly EXEC_PATH

EXEC_NAME="$(basename "$EXEC_PATH")"
BASE_DIR="$(dirname "$EXEC_PATH")"
readonly EXEC_NAME BASE_DIR

readonly IRODS_RELEASE='4.2.12'

readonly REPO=cyverse
readonly IMAGE_NAME=irods
BASE_DIR="$(dirname "$(readlink --canonicalize "$0")")"
readonly BASE_DIR

main() {
local opts
if ! opts="$(getopt --longoptions push --name "$EXEC_NAME" --options p -- "$@")"; then
printf 'failed to parse command line\n' >&2
return 1
fi

eval set -- "$opts"

local push

while true; do
case "$1" in
-p|--push)
push=push
shift
;;
--)
shift
break
;;
*)
printf 'unknown option: %s\n' "$1" >&2
return 1
;;
esac
done

local now
now="$(date --utc '+%Y-%m-%dT%H-%M-%S')"

local currentImage="$REPO"/"$IMAGE_NAME":"$IRODS_RELEASE"
local newImage="$REPO"/"$IMAGE_NAME":"$IRODS_RELEASE"_"$now"

docker pull "$currentImage" 2> /dev/null || true

local currentId
currentId="$(docker image inspect "$currentImage" 2> /dev/null | jq .[0].Id)" || true

docker build --tag "$newImage" "$BASE_DIR"

local newId
newId="$(docker image inspect "$newImage" | jq .[0].Id)"

if [[ "$newId" != "${currentId-}" ]]; then
docker tag "$newImage" "$currentImage"

if [[ -n "${push-}" ]]; then
docker push "$newImage"
docker push "$currentImage"
fi
else
docker rmi "$newImage"
fi
docker build --tag cyverse/irods:new "$BASE_DIR"
}

main "$@"
48 changes: 48 additions & 0 deletions publish
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# Usage:
# publish
#
# This program publishes the cyverse/irods image on Dockerhub. Each build is
# tagged with `latest`, iRODS version, and ISO 8601 style build time with the
# form `version_time`, e.g., `4.2.12_2023-06-18T12-32-00`.

set -o errexit -o nounset -o pipefail

readonly IRODS_RELEASE='4.2.12'

readonly IMAGE_NAME=cyverse/irods
readonly NEW_IMAGE="$IMAGE_NAME":new
readonly CUR_IMAGE="$IMAGE_NAME":latest
readonly VER_IMAGE="$IMAGE_NAME":"$IRODS_RELEASE"

main() {
local newId
newId="$(docker image inspect "$NEW_IMAGE" | jq .[0].Id)"

local curId
if docker pull "$IMAGE_NAME" 2> /dev/null; then
curId="$(docker image inspect "$CUR_IMAGE" 2> /dev/null | jq .[0].Id)" || true
fi

if [[ "$newId" != "${curId-}" ]]; then
local now
now="$(date --utc '+%Y-%m-%dT%H-%M-%S')"

local tag
for tag in "$IRODS_RELEASE"_"$now" "$IRODS_RELEASE" latest; do
publish "$tag"
done
fi
}

publish() {
local tag="$1"

local imageTag="$IMAGE_NAME":"$tag"

docker tag "$NEW_IMAGE" "$imageTag"
docker push "$imageTag"
}

main "$@"
2 changes: 1 addition & 1 deletion test/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM cyverse/irods:latest
FROM cyverse/irods:new

USER root

Expand Down

0 comments on commit 976070b

Please sign in to comment.