Skip to content

Commit 031f7bf

Browse files
authored
refactor: extract scripts from pull, push and update-descriptions (#120)
* refactor: extract scripts from pull, push and update-descriptions * ci: remove RC009
1 parent 2e1e4e4 commit 031f7bf

File tree

7 files changed

+63
-22
lines changed

7 files changed

+63
-22
lines changed

.circleci/config.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ workflows:
1616
tags:
1717
only: /.*/
1818
- orb-tools/review:
19-
exclude: RC009
2019
filters:
2120
tags:
2221
only: /.*/

src/commands/pull.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ steps:
1616
steps:
1717
- run:
1818
name: Docker pull
19-
command: |
20-
echo "<<parameters.images>>" | sed -n 1'p' | tr ',' '\n' | while read image; do
21-
echo "Pulling ${image}";
22-
docker pull ${image} <<#parameters.ignore-docker-pull-error>>|| true<</parameters.ignore-docker-pull-error>>
23-
done
19+
environment:
20+
PARAM_IMAGES: <<parameters.images>>
21+
PARAM_IGNORE_DOCKER_PULL_ERROR: <<parameters.ignore-docker-pull-error>>
22+
command: << include(scripts/pull.sh) >>

src/commands/push.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ parameters:
2929
steps:
3030
- deploy:
3131
name: <<parameters.step-name>>
32+
environment:
33+
PARAM_REGISTRY: <<parameters.registry>>
34+
PARAM_IMAGE: <<parameters.image>>
35+
PARAM_TAG: <<parameters.tag>>
36+
PARAM_DIGEST_PATH: <<parameters.digest-path>>
3237
command: |
3338
IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>"
3439
for tag in "${DOCKER_TAGS[@]}"; do

src/commands/update-description.yml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,11 @@ parameters:
3838
steps:
3939
- deploy:
4040
name: Update description
41-
command: |
42-
if [ "<<parameters.registry>>" != "docker.io" ]; then
43-
echo "Registry is not set to Docker Hub. Exiting"
44-
exit 1
45-
fi
46-
DESCRIPTION="<<parameters.path>>/<<parameters.readme>>"
47-
PAYLOAD="username=$<<parameters.docker-username>>&password=$<<parameters.docker-password>>"
48-
JWT=$(curl -s -d $PAYLOAD https://hub.docker.com/v2/users/login/ | jq -r .token)
49-
HEADER="Authorization: JWT $JWT"
50-
URL="https://hub.docker.com/v2/repositories/<<parameters.image>>/"
51-
STATUS=$(curl -s -o /dev/null -w %{http_code} -X PATCH -H "$HEADER" --data-urlencode full_description@$DESCRIPTION $URL)
52-
if [ $STATUS -ne 200 ]; then
53-
echo "Could not update image description"
54-
echo "Error code: $STATUS"
55-
exit 1
56-
fi
41+
environment:
42+
PARAM_README: <<parameters.readme>>
43+
PARAM_PATH: <<parameters.path>>
44+
PARAM_REGISTRY: <<parameters.registry>>
45+
PARAM_IMAGE: <<parameters.image>>
46+
PARAM_DOCKER_USERNAME: <<parameters.docker-username>>
47+
PARAM_DOCKER_PASSWORD: <<parameters.docker-password>>
48+
command: << include(scripts/update-description.sh) >>

src/scripts/pull.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
echo "$PARAM_IMAGES" | sed -n 1'p' | tr ',' '\n' | while read -r image; do
4+
echo "Pulling ${image}";
5+
6+
if [ "$PARAM_IGNORE_DOCKER_PULL_ERROR" -eq 1 ]; then
7+
docker pull "${image}" || true;
8+
else
9+
docker pull "${image}";
10+
fi
11+
done

src/scripts/push.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env bash
2+
3+
IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG"
4+
5+
for tag in "${DOCKER_TAGS[@]}"; do
6+
docker push "$PARAM_REGISTRY"/"$PARAM_IMAGE":${tag}
7+
done
8+
9+
if [ -n "$PARAM_DIGEST_PATH" ]; then
10+
mkdir -p "$(dirname "$PARAM_DIGEST_PATH")"
11+
IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG"
12+
docker image inspect --format="{{index .RepoDigests 0}}" "$PARAM_REGISTRY"/"$PARAM_IMAGE":"${DOCKER_TAGS[0]}" > "$PARAM_DIGEST_PATH"
13+
fi

src/scripts/update-description.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
if [ "$PARAM_REGISTRY" != "docker.io" ]; then
4+
echo "Registry is not set to Docker Hub. Exiting"
5+
exit 1
6+
fi
7+
8+
USERNAME=${!PARAM_DOCKER_USERNAME}
9+
PASSWORD=${!PARAM_DOCKER_PASSWORD}
10+
11+
DESCRIPTION="$PARAM_PATH/$PARAM_README"
12+
PAYLOAD="username=$USERNAME&password=$PASSWORD"
13+
JWT=$(curl -s -d "$PAYLOAD" https://hub.docker.com/v2/users/login/ | jq -r .token)
14+
HEADER="Authorization: JWT $JWT"
15+
URL="https://hub.docker.com/v2/repositories/$PARAM_IMAGE/"
16+
STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X PATCH -H "$HEADER" --data-urlencode full_description@$DESCRIPTION $URL)
17+
18+
if [ $STATUS -ne 200 ]; then
19+
echo "Could not update image description"
20+
echo "Error code: $STATUS"
21+
exit 1
22+
fi

0 commit comments

Comments
 (0)