diff --git a/.circleci/config.yml b/.circleci/config.yml index 4dfc88e..ef91144 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -16,7 +16,6 @@ workflows: tags: only: /.*/ - orb-tools/review: - exclude: RC009 filters: tags: only: /.*/ diff --git a/src/commands/pull.yml b/src/commands/pull.yml index c6b9ffb..53dbf83 100644 --- a/src/commands/pull.yml +++ b/src/commands/pull.yml @@ -16,8 +16,7 @@ steps: steps: - run: name: Docker pull - command: | - echo "<>" | sed -n 1'p' | tr ',' '\n' | while read image; do - echo "Pulling ${image}"; - docker pull ${image} <<#parameters.ignore-docker-pull-error>>|| true<> - done + environment: + PARAM_IMAGES: <> + PARAM_IGNORE_DOCKER_PULL_ERROR: <> + command: << include(scripts/pull.sh) >> diff --git a/src/commands/push.yml b/src/commands/push.yml index 933bb8b..da17bdc 100644 --- a/src/commands/push.yml +++ b/src/commands/push.yml @@ -29,6 +29,11 @@ parameters: steps: - deploy: name: <> + environment: + PARAM_REGISTRY: <> + PARAM_IMAGE: <> + PARAM_TAG: <> + PARAM_DIGEST_PATH: <> command: | IFS="," read -ra DOCKER_TAGS \<<< "<< parameters.tag >>" for tag in "${DOCKER_TAGS[@]}"; do diff --git a/src/commands/update-description.yml b/src/commands/update-description.yml index fdbf09e..6d5549f 100644 --- a/src/commands/update-description.yml +++ b/src/commands/update-description.yml @@ -38,19 +38,11 @@ parameters: steps: - deploy: name: Update description - command: | - if [ "<>" != "docker.io" ]; then - echo "Registry is not set to Docker Hub. Exiting" - exit 1 - fi - DESCRIPTION="<>/<>" - PAYLOAD="username=$<>&password=$<>" - JWT=$(curl -s -d $PAYLOAD https://hub.docker.com/v2/users/login/ | jq -r .token) - HEADER="Authorization: JWT $JWT" - URL="https://hub.docker.com/v2/repositories/<>/" - STATUS=$(curl -s -o /dev/null -w %{http_code} -X PATCH -H "$HEADER" --data-urlencode full_description@$DESCRIPTION $URL) - if [ $STATUS -ne 200 ]; then - echo "Could not update image description" - echo "Error code: $STATUS" - exit 1 - fi + environment: + PARAM_README: <> + PARAM_PATH: <> + PARAM_REGISTRY: <> + PARAM_IMAGE: <> + PARAM_DOCKER_USERNAME: <> + PARAM_DOCKER_PASSWORD: <> + command: << include(scripts/update-description.sh) >> diff --git a/src/scripts/pull.sh b/src/scripts/pull.sh new file mode 100644 index 0000000..741f167 --- /dev/null +++ b/src/scripts/pull.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +echo "$PARAM_IMAGES" | sed -n 1'p' | tr ',' '\n' | while read -r image; do + echo "Pulling ${image}"; + + if [ "$PARAM_IGNORE_DOCKER_PULL_ERROR" -eq 1 ]; then + docker pull "${image}" || true; + else + docker pull "${image}"; + fi +done \ No newline at end of file diff --git a/src/scripts/push.sh b/src/scripts/push.sh new file mode 100644 index 0000000..70efb22 --- /dev/null +++ b/src/scripts/push.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG" + +for tag in "${DOCKER_TAGS[@]}"; do + docker push "$PARAM_REGISTRY"/"$PARAM_IMAGE":${tag} +done + +if [ -n "$PARAM_DIGEST_PATH" ]; then + mkdir -p "$(dirname "$PARAM_DIGEST_PATH")" + IFS="," read -ra DOCKER_TAGS <<< "$PARAM_TAG" + docker image inspect --format="{{index .RepoDigests 0}}" "$PARAM_REGISTRY"/"$PARAM_IMAGE":"${DOCKER_TAGS[0]}" > "$PARAM_DIGEST_PATH" +fi \ No newline at end of file diff --git a/src/scripts/update-description.sh b/src/scripts/update-description.sh new file mode 100644 index 0000000..a1006c9 --- /dev/null +++ b/src/scripts/update-description.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +if [ "$PARAM_REGISTRY" != "docker.io" ]; then + echo "Registry is not set to Docker Hub. Exiting" + exit 1 +fi + +USERNAME=${!PARAM_DOCKER_USERNAME} +PASSWORD=${!PARAM_DOCKER_PASSWORD} + +DESCRIPTION="$PARAM_PATH/$PARAM_README" +PAYLOAD="username=$USERNAME&password=$PASSWORD" +JWT=$(curl -s -d "$PAYLOAD" https://hub.docker.com/v2/users/login/ | jq -r .token) +HEADER="Authorization: JWT $JWT" +URL="https://hub.docker.com/v2/repositories/$PARAM_IMAGE/" +STATUS=$(curl -s -o /dev/null -w '%{http_code}' -X PATCH -H "$HEADER" --data-urlencode full_description@$DESCRIPTION $URL) + +if [ $STATUS -ne 200 ]; then + echo "Could not update image description" + echo "Error code: $STATUS" + exit 1 +fi \ No newline at end of file