Skip to content
This repository has been archived by the owner on Jun 22, 2024. It is now read-only.

Commit

Permalink
Added the functionality to add browser versions to the Docker Hub tag…
Browse files Browse the repository at this point in the history
…s. Also, updated the 'latest' tag.
  • Loading branch information
jamesmortensen committed Apr 29, 2022
1 parent 5709ba6 commit 7754dc7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ jobs:
- run:
name: "Tag browser images and update latest tag"
command: |
NAME=${NAMESPACE} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} PUSH_IMAGE=true PLATFORMS=${PLATFORMS} make tag_and_push_multi_arch_browser_images
NAME=${NAMESPACE} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} PUSH_IMAGE=true make tag_and_push_multi_arch_browser_images
NAME=${NAMESPACE} VERSION=${BRANCH} BUILD_DATE=${BUILD_DATE} make tag_multi_arch_latest
- run:
name: "Generate release notes"
Expand Down
18 changes: 9 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,19 @@ tag_latest:
tag_and_push_multi_arch_browser_images: tag_and_push_multi_arch_chromium_images tag_and_push_multi_arch_firefox_images

tag_and_push_multi_arch_chromium_images:
./tag_and_push_multi-arch_browser_images.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) $(PUSH_IMAGE) chromium $(PLATFORMS)
./tag_and_push_multi-arch_browser_images.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) $(PUSH_IMAGE) chromium

tag_and_push_multi_arch_firefox_images:
./tag_and_push_multi-arch_browser_images.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) $(PUSH_IMAGE) firefox $(PLATFORMS)
./tag_and_push_multi-arch_browser_images.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) $(PUSH_IMAGE) firefox

tag_multi_arch_latest:
docker tag $(NAME)/base:$(TAG_VERSION) $(NAME)/base:latest
docker tag $(NAME)/hub:$(TAG_VERSION) $(NAME)/hub:latest
docker tag $(NAME)/node-base:$(TAG_VERSION) $(NAME)/node-base:latest
docker tag $(NAME)/node-chromium:$(TAG_VERSION) $(NAME)/node-chromium:latest
docker tag $(NAME)/node-firefox:$(TAG_VERSION) $(NAME)/node-firefox:latest
docker tag $(NAME)/standalone-chromium:$(TAG_VERSION) $(NAME)/standalone-chromium:latest
docker tag $(NAME)/standalone-firefox:$(TAG_VERSION) $(NAME)/standalone-firefox:latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) base latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) hub latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) node-base latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) node-chromium latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) node-firefox latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) standalone-chromium latest
./tag-and-push-multi-arch-image.sh $(VERSION) $(BUILD_DATE) $(NAMESPACE) standalone-firefox latest

release_latest:
docker push $(NAME)/base:latest
Expand Down
56 changes: 56 additions & 0 deletions get-image-sha256-digest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package main

import (
"io/ioutil"
"log"
"net/http"
"fmt"
"encoding/json"
"os"
)

type Latest struct {
Images []struct {
Architecture string `json:"architecture"`
Digest string `json:"digest"`
}
}


func main() {
argLen := len(os.Args)
if argLen < 2 {
showUsage()
os.Exit(1)
}

url := os.Args[1] // https://hub.docker.com/v2/repositories/selenium/standalone-chrome/tags/latest/
resp, err := http.Get(url)
if err != nil {
log.Fatalln(err)
}

body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatalln(err)
}

var jsonResp Latest
sb := string(body)
json.Unmarshal([]byte(sb), &jsonResp)

for _, image := range jsonResp.Images {
fmt.Printf(image.Architecture + " " + image.Digest + "\n")
}
}

func showUsage() {
fmt.Println(`Usage:
get-image-sha256-digest TAG_URL
TAG_URL -> URL for a container image manifest (Required)
Example Usage:
$ get-image-sha256-digest https://hub.docker.com/v2/repositories/selenium/standalone-chrome/tags/latest/
`)
}
25 changes: 25 additions & 0 deletions tag-and-push-multi-arch-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/bash

VERSION=$1
BUILD_DATE=$2
NAMESPACE="${3:-seleniarm}"
IMAGE=$4
NEW_TAG=$5

if [ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] || [ -z "$4" ] || [ -z "$5" ]; then
echo "Be sure to pass in all of the values"
exit 1
fi


AMD64_DIGEST=`go run get-image-sha256-digest.go https://hub.docker.com/v2/repositories/$NAMESPACE/$IMAGE/tags/$VERSION-$BUILD_DATE/ | grep -w "amd64" | awk '{print $2}'`
ARM_DIGEST=`go run get-image-sha256-digest.go https://hub.docker.com/v2/repositories/$NAMESPACE/$IMAGE/tags/$VERSION-$BUILD_DATE/ | grep -w "arm" | awk '{print $2}'`
ARM64_DIGEST=`go run get-image-sha256-digest.go https://hub.docker.com/v2/repositories/$NAMESPACE/$IMAGE/tags/$VERSION-$BUILD_DATE/ | grep -w "arm64" | awk '{print $2}'`

docker manifest create $NAMESPACE/$IMAGE:$NEW_TAG \
--amend $NAMESPACE/$IMAGE@$AMD64_DIGEST \
--amend $NAMESPACE/$IMAGE@$ARM_DIGEST \
--amend $NAMESPACE/$IMAGE@$ARM64_DIGEST

docker manifest push $NAMESPACE/$IMAGE:$NEW_TAG

27 changes: 6 additions & 21 deletions tag_and_push_multi-arch_browser_images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ BUILD_DATE=$2
NAMESPACE=$3
PUSH_IMAGE="${4:-false}"
BROWSER=$5
PLATFORMS=$6

TAG_VERSION=${VERSION}-${BUILD_DATE}

Expand Down Expand Up @@ -53,20 +52,13 @@ chromium)
${CHROME_SHORT_VERSION}
)

cd NodeChromium
NODE_CHROMIUM_TAGS=""
STANDALONE_CHROMIUM_TAGS=""
for chrome_tag in "${CHROME_TAGS[@]}"
do
#docker tag ${NAMESPACE}/node-chromium:${TAG_VERSION} ${NAMESPACE}/node-chromium:${chrome_tag}
#docker tag ${NAMESPACE}/standalone-chromium:${TAG_VERSION} ${NAMESPACE}/standalone-chromium:${chrome_tag}
NODE_CHROMIUM_TAGS+=" -t ${NAME}/node-chromium:${chrome_tag}"
STANDALONE_CHROMIUM_TAGS+=" -t ${NAME}/standalone-chromium:${chrome_tag}"
if [ "${PUSH_IMAGE}" = true ]; then
sh tag-and-push-multi-arch-image.sh $VERSION $BUILD_DATE $NAME node-chromium ${chrome_tag}
sh tag-and-push-multi-arch-image.sh $VERSION $BUILD_DATE $NAME standalone-chromium ${chrome_tag}
fi
done
if [ "${PUSH_IMAGE}" = true ]; then
cd ../NodeChromium && docker buildx build --platform ${PLATFORMS} --push ${NODE_CHROMIUM_TAGS} .
cd ../StandaloneChromium && docker buildx build --platform ${PLATFORMS} --push ${STANDALONE_CHROMIUM_TAGS} .
fi

;;
firefox)
Expand Down Expand Up @@ -101,18 +93,11 @@ firefox)
${FIREFOX_SHORT_VERSION}
)

#cd NodeFirefox
NODE_FIREFOX_TAGS=""
STANDALONE_FIREFOX_TAGS=""
for firefox_tag in "${FIREFOX_TAGS[@]}"
do
#docker tag ${NAMESPACE}/node-firefox:${TAG_VERSION} ${NAMESPACE}/node-firefox:${firefox_tag}
#docker tag ${NAMESPACE}/standalone-firefox:${TAG_VERSION} ${NAMESPACE}/standalone-firefox:${firefox_tag}
NODE_FIREFOX_TAGS+=" -t ${NAME}/node-firefox:${firefox_tag}"
STANDALONE_FIREFOX_TAGS+=" -t ${NAME}/standalone-firefox:${firefox_tag}"
if [ "${PUSH_IMAGE}" = true ]; then
cd ../NodeFirefox && docker buildx build --platform ${PLATFORMS} --push ${NODE_FIREFOX_TAGS} .
cd ../StandaloneFirefox && docker buildx build --platform ${PLATFORMS} --push ${STANDALONE_FIREFOX_TAGS} .
sh tag-and-push-multi-arch-image.sh $VERSION $BUILD_DATE $NAME node-firefox ${firefox_tag}
sh tag-and-push-multi-arch-image.sh $VERSION $BUILD_DATE $NAME standalone-firefox ${firefox_tag}
fi
done

Expand Down

0 comments on commit 7754dc7

Please sign in to comment.