Class: Docker::PushLatest

Inherits:
Object
  • Object
show all
Defined in:
lib/scripts/docker/push_latest.rb

Instance Method Summary collapse

Instance Method Details

#runObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/scripts/docker/push_latest.rb', line 3

def run
  latest_branch = env_fetch("DOCKER_LATEST_BRANCH", "master")

  branch = `git rev-parse --abbrev-ref HEAD`.strip
  return if branch != latest_branch

  env_require("DOCKER_IMAGE")

  # set image tag if it hasnt been set
  # Default: current git hash
  env_check("IMAGE_TAG", `git rev-parse HEAD`.strip)

  # tag latest image
  command('docker tag "$DOCKER_IMAGE:$IMAGE_TAG" "$DOCKER_IMAGE:latest"')

  # push docker image
  command('docker push "$DOCKER_IMAGE:latest"')
end