Skip to content

Commit f720b63

Browse files
authored
Fix Docker push (#3796)
2 parents 903f8d9 + 9ef6680 commit f720b63

File tree

4 files changed

+59
-26
lines changed

4 files changed

+59
-26
lines changed

ci/lib.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ get_artifacts_url() {
6262
artifacts_url=$(gh api "$workflow_runs_url" | jq -r ".workflow_runs[] | select(.head_branch == \"$version_branch\") | .artifacts_url" | head -n 1)
6363
if [[ -z "$artifacts_url" ]]; then
6464
echo >&2 "ERROR: artifacts_url came back empty"
65-
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"
65+
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"
6666
echo >&2 "URL used for gh API call: $workflow_runs_url"
6767
exit 1
6868
fi

ci/steps/brew-bump.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ main() {
1919
echo "Adding Homebrew/homebrew-core as $(upstream)"
2020
git remote add upstream https://github.com/Homebrew/homebrew-core.git
2121

22-
echo "Fetching upstream commits..."
22+
echo "Fetching upstream Homebrew/hombrew-core commits"
2323
git fetch upstream
2424

25-
echo "Merging in latest changes"
25+
echo "Merging in latest Homebrew/homebrew-core changes"
2626
git merge upstream/master
2727

2828
echo "Pushing changes to cdrci/homebrew-core fork on GitHub"
@@ -37,7 +37,15 @@ main() {
3737

3838
# Find the docs for bump-formula-pr here
3939
# https://github.com/Homebrew/brew/blob/master/Library/Homebrew/dev-cmd/bump-formula-pr.rb#L18
40-
brew bump-formula-pr --force --version="${VERSION}" code-server --no-browse --no-audit
40+
local output
41+
if ! output=$(brew bump-formula-pr --version="${VERSION}" code-server --no-browse --no-audit 2>&1); then
42+
if [[ $output == *"Duplicate PRs should not be opened"* ]]; then
43+
echo "$VERSION is already submitted"
44+
else
45+
echo "$output"
46+
exit 1
47+
fi
48+
fi
4149

4250
# Clean up and remove homebrew-core
4351
cd ..

ci/steps/publish-npm.sh

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ main() {
55
cd "$(dirname "$0")/../.."
66
source ./ci/lib.sh
77

8+
# npm view won't exit with non-zero so we have to check the output.
9+
local hasVersion
10+
hasVersion=$(npm view "code-server@$VERSION" version)
11+
if [[ $hasVersion == "$VERSION" ]]; then
12+
echo "$VERSION is already published"
13+
return
14+
fi
15+
816
if [[ ${CI-} ]]; then
917
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
1018
fi

ci/steps/push-docker-manifest.sh

+39-22
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,54 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
main() {
5-
cd "$(dirname "$0")/../.."
6-
source ./ci/lib.sh
7-
8-
download_artifact release-images ./release-images
9-
if [[ ${CI-} ]]; then
10-
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
4+
# See if this version already exists on Docker Hub.
5+
function version_exists() {
6+
local output
7+
output=$(curl --silent "https://index.docker.io/v1/repositories/codercom/code-server/tags/$VERSION")
8+
if [[ $output == "Tag not found" ]]; then
9+
return 1
10+
else
11+
return 0
1112
fi
13+
}
14+
15+
# Import and push the Docker image for the provided arch.
16+
push() {
17+
local arch=$1
18+
local tag="codercom/code-server-$arch:$VERSION"
1219

13-
for img in ./release-images/*; do
14-
docker load -i "$img"
15-
done
20+
docker import "./release-images/code-server-$arch-$VERSION.tar" "$tag"
1621

17-
# We have to ensure the amd64 and arm64 images exist on the remote registry
18-
# in order to build the manifest.
19-
# We don't put the arch in the tag to avoid polluting the main repository.
20-
# These other repositories are private so they don't pollute our organization namespace.
21-
docker push "codercom/code-server-amd64:$VERSION"
22-
docker push "codercom/code-server-arm64:$VERSION"
22+
# We have to ensure the images exists on the remote registry in order to build
23+
# the manifest. We don't put the arch in the tag to avoid polluting the main
24+
# repository. These other repositories are private so they don't pollute our
25+
# organization namespace.
26+
docker push "$tag"
2327

2428
export DOCKER_CLI_EXPERIMENTAL=enabled
2529

2630
docker manifest create "codercom/code-server:$VERSION" \
27-
"codercom/code-server-amd64:$VERSION" \
28-
"codercom/code-server-arm64:$VERSION"
31+
"codercom/code-server-$arch:$VERSION" \
32+
"codercom/code-server-$arch:$VERSION"
2933
docker manifest push --purge "codercom/code-server:$VERSION"
34+
}
35+
36+
main() {
37+
cd "$(dirname "$0")/../.."
38+
source ./ci/lib.sh
39+
40+
if version_exists; then
41+
echo "$VERSION is already pushed"
42+
return
43+
fi
44+
45+
download_artifact release-images ./release-images
46+
if [[ ${CI-} ]]; then
47+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
48+
fi
3049

31-
docker manifest create "codercom/code-server:latest" \
32-
"codercom/code-server-amd64:$VERSION" \
33-
"codercom/code-server-arm64:$VERSION"
34-
docker manifest push --purge "codercom/code-server:latest"
50+
push "amd64"
51+
push "arm64"
3552
}
3653

3754
main "$@"

0 commit comments

Comments
 (0)