Sign inSign up

ligadigital/pipe-docker-push

By ligadigital

Updated 8 months ago

Image
0

10K+

ligadigital/pipe-docker-push repository overview

Bitbucket Pipelines Pipe: docker-push

This BitBucket pipe will build docker containers, push them to dockerhub and store results info in a file. Even though majority of dockerfiles are able to build applications from scrach, it is better to run this step after the application has been complied in parallel for each target earlier and reuse the artifacts. This step should be followed by a trigger of Kuberentes deployment BB pipe.

Configuration files

deployment/docker-push-config.json - Using this configuration file is optional, all of this configuration can be expressed using pipe parameters. docker-images.json - result file containg information about created and pushed docker images

YAML Definition

Add the following snippet to the script section of your bitbucket-pipelines.yml file:

- step:
  name: "Push docker Image"
  script:
    - pipe: "docker://ligadigital/pipe-docker-push:latest"
      variables:
        DOCKER_USER:     $DOCKER_USER
        DOCKER_PASSWORD: $DOCKER_PASSWORD

Variables

VariableDefaultRequiredDescription
DOCKER_USERyesDockerhub credentials
DOCKER_PASSWORDyesDockerhub credentials
TARGETS""noSpace separated list of targets to build
TAG_LATEST""noIf true pushes latest tag
TAG_FORCEfalsenoIf true uses latest tag in commit
DOCKER_ORG"ligadigital"noDockerhub org
DOCKER_REPO$BITBUCKET_REPO_SLUGnoDocker image repo
DOCKER_CONTEXT"."noDocker build context
DOCKER_FILE"Dockerfile"noDefault Dockerfile
DOCKER_BUILDKIT0noUse buildkit
BUILD_ARGS""noSpace separated list of docker build arguments to be passed
VERSION``noDockerhub image tag
VERSION_FORMAT"AUTO"noVersion format
ARTIFACT_FILEdocker-images.jsonnoFile with information about built images
CONFIG_FILEdeployment/docker-push-config.jsonno
SSH_PRIVATE_KEY""noSSH key to be passed as docker build arg
ACTIONbuildnoOne of build or merge. build will build and push docker imagesandmergewill concat multipleARTIFACT_FILE` files into one that can be easily passed for further processing.

VERSION variable resolution

Examples

Push one image for all targets: ligadigital/<project>:<version>

- step:
  name: "Push docker Image"
  script:
    - pipe: "docker://ligadigital/pipe-docker-push:latest"
      artifacts: ['docker-images.json']
      variables:
        DOCKER_USER:     $DOCKER_USER
        DOCKER_PASSWORD: $DOCKER_PASSWORD

Push images for multiple targets: ligadigital/<project>:<version>-<target>

- step:
  name: "Push docker Image"
  script:
    - pipe: "docker://ligadigital/pipe-docker-push:latest"
      artifacts: ['docker-images.json']
      variables:
        DOCKER_USER:     $DOCKER_USER
        DOCKER_PASSWORD: $DOCKER_PASSWORD
        TARGETS:         "ln-test pi-test ld-test"

Push multiple images from one repository, example 1:

  • ligadigital/project-a:<version>
  • ligadigital/project-b:<version>-<target>

deployment/docker-push-config.json

{
  "images": [
    {
      "name": "ln-api-myliga-base",
      "dockerfile": "docker/base/Dockerfile"
    },
    {
      "name": "ln-api-myliga-myliga",
      "dockerfile": "docker/myliga/Dockerfile"
    },
    {
      "name": "ln-api-myliga-server",
      "dockerfile": "docker/server/Dockerfile"
    },
    {
      "name": "ln-api-myliga-storage",
      "dockerfile": "docker/storage/Dockerfile"
    },
    {
      "name": "ln-api-myliga-schedule",
      "dockerfile": "docker/schedule/Dockerfile"
    }
  ]
}
pushTestStep: &pushTestStep
  step:
    name:      "Push Docker Images"
    artifacts: ['docker-images.json']
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:1"
        variables:
          TARGETS:         "ln-test pi-test ld-test"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD

pushReleaseStep: &pushReleaseStep
  step:
    name: "Push Docker Images"
    artifacts: ['docker-images.json']
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:1"
        variables:
          TARGETS:         "ln-staging pi-staging ln-production pi-production"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD

Push multiple images from one repository, example 2:

  • ligadigital/project-a:<version>
  • ligadigital/project-b:<version>-<target>
pushDockerLiganovaStep: &pushDockerLiganovaStep
  step:
    name: "Push Docker Image (Liganova)"
    artifacts: ['docker-images.liganova.json']
    script:
      - pipe: docker://ligadigital/pipe-docker-push:1
        variables:
          ARTIFACT_FILE:   'docker-images.liganova.json'
          TARGETS:         "ln-test ln-staging ln-production"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD
          SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY
          BUILD_ARGS:      "CONFIG_TARGET=liganova"

pushDockerParasolStep: &pushDockerParasolStep
  step:
    name: "Push Docker Image (Parasol)"
    artifacts: ['docker-images.parasol.json']
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:1"
        variables:
          ARTIFACT_FILE:   'docker-images.parasol.json'
          TARGETS:         "pi-test pi-staging pi-production"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD
          SSH_PRIVATE_KEY: $SSH_PRIVATE_KEY
          BUILD_ARGS:      "CONFIG_TARGET=parasol"

pushDockerMergeStep: &pushDockerMergeStep
  step:
    name: "Merge Docker artifacts file"
    artifacts: ['docker-images.json']
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:1"
        variables:
          ACTION: "merge"

Push images from one repository (untested):

  • ligadigital/project-a:<version>
  • ligadigital/project-b:<version>-<target>
- parallel:
  - step:
    name: "Push docker Image: project-a"
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:latest"
        artifacts: ['docker-images.project-a.json']
        variables:
          ACTION:          "build"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD
          IMAGES_FILE:     "docker-images.project-a.json"
          DOCKER_REPO:     "project-a"
          DOCKER_CONTEXT:  "project-a"

  - step:
    name: "Push docker Image: project-b"
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:latest"
        artifacts: ['docker-images.project-b.json']
        variables:
          ACTION:          "build"
          DOCKER_USER:     $DOCKER_USER
          DOCKER_PASSWORD: $DOCKER_PASSWORD
          IMAGES_FILE:     "docker-images.project-b.json"
          TARGETS:         "ln-test pi-test ld-test"
          DOCKER_REPO:     "project-b"
          DOCKER_CONTEXT:  "project-b"
          DOCKER_IMAGES:   '[{ "" }]'

- step:
    name: "Merge docker-images.json"
    script:
      - pipe: "docker://ligadigital/pipe-docker-push:latest"
        artifacts: ['docker-images.json']
        variables:
          ACTION: "merge"

Tag summary

Content type

Image

Digest

sha256:22137dc2c

Size

13.6 MB

Last updated

8 months ago

docker pull ligadigital/pipe-docker-push