From 8608d8ec74e91ae84dce21df12feddcf23ae59d8 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 16 Jul 2021 16:24:50 -0500 Subject: [PATCH 1/5] Fix Docker push It seems we need to use `docker import` with the output from `docker buildx` rather than `docker load` like we were doing when we used `docker save`. --- ci/steps/push-docker-manifest.sh | 45 ++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/ci/steps/push-docker-manifest.sh b/ci/steps/push-docker-manifest.sh index 08d0fdacf..62ac03171 100755 --- a/ci/steps/push-docker-manifest.sh +++ b/ci/steps/push-docker-manifest.sh @@ -1,6 +1,27 @@ #!/usr/bin/env bash set -euo pipefail +# Import and push the Docker image for the provided arch. +push() { + local arch=$1 + local tag="codercom/code-server-$arch:$VERSION" + + docker import "./release-images/code-server-$arch-$VERSION.tar" "$tag" + + # We have to ensure the images exists on the remote registry in order to build + # the manifest. We don't put the arch in the tag to avoid polluting the main + # repository. These other repositories are private so they don't pollute our + # organization namespace. + docker push "$tag" + + export DOCKER_CLI_EXPERIMENTAL=enabled + + docker manifest create "codercom/code-server:$VERSION" \ + "codercom/code-server-$arch:$VERSION" \ + "codercom/code-server-$arch:$VERSION" + docker manifest push --purge "codercom/code-server:$VERSION" +} + main() { cd "$(dirname "$0")/../.." source ./ci/lib.sh @@ -10,28 +31,8 @@ main() { echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin fi - for img in ./release-images/*; do - docker load -i "$img" - done - - # We have to ensure the amd64 and arm64 images exist on the remote registry - # in order to build the manifest. - # We don't put the arch in the tag to avoid polluting the main repository. - # These other repositories are private so they don't pollute our organization namespace. - docker push "codercom/code-server-amd64:$VERSION" - docker push "codercom/code-server-arm64:$VERSION" - - export DOCKER_CLI_EXPERIMENTAL=enabled - - docker manifest create "codercom/code-server:$VERSION" \ - "codercom/code-server-amd64:$VERSION" \ - "codercom/code-server-arm64:$VERSION" - docker manifest push --purge "codercom/code-server:$VERSION" - - docker manifest create "codercom/code-server:latest" \ - "codercom/code-server-amd64:$VERSION" \ - "codercom/code-server-arm64:$VERSION" - docker manifest push --purge "codercom/code-server:latest" + push "amd64" + push "arm64" } main "$@" From 3c0799fa59e9a23eaee1b14f25b8aa104c7e6d9f Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 16 Jul 2021 16:44:00 -0500 Subject: [PATCH 2/5] Skip npm publish if already published This helps make the publish workflow idempotent. --- ci/steps/publish-npm.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 7bd497d00..ea65780d8 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -5,6 +5,14 @@ main() { cd "$(dirname "$0")/../.." source ./ci/lib.sh + # npm view won't exit with non-zero so we have to check the output. + local hasVersion + hasVersion=$(npm view "code-server@$VERSION" version) + if [[ $hasVersion == "$VERSION" ]]; then + echo "$VERSION is already published" + return + fi + if [[ ${CI-} ]]; then echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc fi From 4cfa384bb45263358a61d1969ad0d5fa9a28ff57 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 16 Jul 2021 17:02:18 -0500 Subject: [PATCH 3/5] Skip brew if already published --- ci/steps/brew-bump.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/ci/steps/brew-bump.sh b/ci/steps/brew-bump.sh index fd5d97001..f3f9be7c8 100755 --- a/ci/steps/brew-bump.sh +++ b/ci/steps/brew-bump.sh @@ -19,10 +19,10 @@ main() { echo "Adding Homebrew/homebrew-core as $(upstream)" git remote add upstream https://github.com/Homebrew/homebrew-core.git - echo "Fetching upstream commits..." + echo "Fetching upstream Homebrew/hombrew-core commits" git fetch upstream - echo "Merging in latest changes" + echo "Merging in latest Homebrew/homebrew-core changes" git merge upstream/master echo "Pushing changes to cdrci/homebrew-core fork on GitHub" @@ -37,7 +37,15 @@ main() { # Find the docs for bump-formula-pr here # https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18 - brew bump-formula-pr --force --version="${VERSION}" code-server --no-browse --no-audit + local output + if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then + if [[ $output == *"Duplicate PRs should not be opened"* ]]; then + echo "$VERSION is already submitted" + else + echo "$output" + exit 1 + fi + fi # Clean up and remove homebrew-core cd .. From a32df56f9925dae139620eda67e59c8978889c3b Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 16 Jul 2021 17:35:36 -0500 Subject: [PATCH 4/5] Skip Docker if already pushed --- ci/steps/push-docker-manifest.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ci/steps/push-docker-manifest.sh b/ci/steps/push-docker-manifest.sh index 62ac03171..e866e606b 100755 --- a/ci/steps/push-docker-manifest.sh +++ b/ci/steps/push-docker-manifest.sh @@ -1,6 +1,17 @@ #!/usr/bin/env bash set -euo pipefail +# See if this version already exists on Docker Hub. +function version_exists() { + local output + output=$(curl --silent "https://index.docker.io/v1/repositories/codercom/code-server/tags/$VERSION") + if [[ $output == "Tag not found" ]]; then + return 1 + else + return 0 + fi +} + # Import and push the Docker image for the provided arch. push() { local arch=$1 @@ -26,6 +37,11 @@ main() { cd "$(dirname "$0")/../.." source ./ci/lib.sh + if version_exists; then + echo "$VERSION is already pushed" + return + fi + download_artifact release-images ./release-images if [[ ${CI-} ]]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin From 9ef6680adc919b69d68e1e580779d307c2463819 Mon Sep 17 00:00:00 2001 From: Asher Date: Fri, 16 Jul 2021 17:37:26 -0500 Subject: [PATCH 5/5] Fix incorrect version var in artifact script --- ci/lib.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/lib.sh b/ci/lib.sh index 39e1a3ec0..5021f99e7 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -62,7 +62,7 @@ get_artifacts_url() { artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1) if [[ -z "$artifacts_url" ]]; then echo >&2 "ERROR: artifacts_url came back empty" - echo >&2 "We looked for a successful run triggered by a pull_request with for code-server version: $code_server_version and a branch named $version_branch" + echo >&2 "We looked for a successful run triggered by a pull_request with for code-server version: $VERSION and a branch named $version_branch" echo >&2 "URL used for gh API call: $workflow_runs_url" exit 1 fi