|
1 | 1 | #!/usr/bin/env bash
|
2 | 2 | set -euo pipefail
|
3 | 3 |
|
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 |
11 | 12 | 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" |
12 | 19 |
|
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" |
16 | 21 |
|
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" |
23 | 27 |
|
24 | 28 | export DOCKER_CLI_EXPERIMENTAL=enabled
|
25 | 29 |
|
26 | 30 | 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" |
29 | 33 | 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 |
30 | 49 |
|
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" |
35 | 52 | }
|
36 | 53 |
|
37 | 54 | main "$@"
|
0 commit comments