user3142695
user3142695

Reputation: 17332

GitLab CI: How to pull specific docker container for deployment

I'm doing the productive deploy in gitlab manually. I'm using docker container. Clicking on the 'Play'-Button in the pipeline list should do the deploy. But how do I get the version of the selected container? Doing this script is always trying to pull the latest version, which should not be. I want to pull the 'selected' container.

deploy_prod:
  stage: deploy
  script:
    - docker pull $CI_REGISTRY_IMAGE     # here selected version is missing
    # ...
  when: manual
  environment:
    name: productive
    url: https://example.com
  only:
    - master

Upvotes: 0

Views: 644

Answers (1)

Jawad
Jawad

Reputation: 4665

As mentioned in the comments to your question, simply use the same script you used to push the image, to pull it in the deploy stage.

Here's an example pull.sh script:

#!/bin/sh
args=("$@")
CI_REGISTRY_IMAGE=${args[0]}

PACKAGE_VERSION=$(cat package.json \
| grep version \
  | head -1 \
  | awk -F: '{ print $2 }' \
  | sed 's/[",]//g' \
  | tr -d '[[:space:]]')
CONTAINER_RELEASE_IMAGE=$CI_REGISTRY_IMAGE\:$PACKAGE_VERSION
docker pull $CONTAINER_RELEASE_IMAGE

Notice the pull instead of the push in the last line.

Then modify your deploy job like this:

deploy_prod:
  stage: deploy
  script:
    - ./pull.sh $CI_REGISTRY_IMAGE
    # ...
  when: manual
  environment:
    name: productive
    url: https://example.com
  only:
    - master

Upvotes: 1

Related Questions