diff --git a/.circleci/config.yml b/.circleci/config.yml index 68a454648..de3339b87 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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" diff --git a/Makefile b/Makefile index 086f671b8..9e6bd4e50 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/get-image-sha256-digest.go b/get-image-sha256-digest.go new file mode 100644 index 000000000..d51b58ca5 --- /dev/null +++ b/get-image-sha256-digest.go @@ -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/ + `) +} diff --git a/tag-and-push-multi-arch-image.sh b/tag-and-push-multi-arch-image.sh new file mode 100755 index 000000000..7e993dced --- /dev/null +++ b/tag-and-push-multi-arch-image.sh @@ -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 + diff --git a/tag_and_push_multi-arch_browser_images.sh b/tag_and_push_multi-arch_browser_images.sh index 20ed3ba23..588cc1e3a 100755 --- a/tag_and_push_multi-arch_browser_images.sh +++ b/tag_and_push_multi-arch_browser_images.sh @@ -5,7 +5,6 @@ BUILD_DATE=$2 NAMESPACE=$3 PUSH_IMAGE="${4:-false}" BROWSER=$5 -PLATFORMS=$6 TAG_VERSION=${VERSION}-${BUILD_DATE} @@ -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) @@ -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