summaryrefslogtreecommitdiffstats
path: root/.circleci/deploy.pl
blob: 5c7d648a626c064d5f277365c12a27b8d1029cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env perl
use 5.10.1;
use strict;
use warnings;

my ($repo, $user, $pass)
  = check_env(qw(DOCKERHUB_REPO DOCKER_USER DOCKER_PASS));
run("docker", "login", "-u", $user, "-p", $pass);

my @docker_tags = ($ENV{CIRCLE_SHA1});

if ($ENV{CIRCLE_TAG}) {
  push @docker_tags, $ENV{CIRCLE_TAG};
}
elsif ($ENV{CIRCLE_BRANCH}) {
  if ($ENV{CIRCLE_BRANCH} eq 'master') {
    push @docker_tags, 'latest';
  }
  else {
    push @docker_tags, $ENV{CIRCLE_BRANCH};
  }
}

say "Pushing tags...";
say "  $_" for @docker_tags;
foreach my $tag (@docker_tags) {
  run("docker", "tag", "bmo", "$repo:$tag");
  run("docker", "push", "$repo:$tag");
}

sub run {
  my (@cmd) = @_;
  my $rv = system(@cmd);
  exit 1 if $rv != 0;
}

sub check_env {
  my (@missing, @found);
  foreach my $name (@_) {
    push @missing, $name unless $ENV{$name};
    push @found, $ENV{$name};
  }

  if (@missing) {
    warn "Missing environmental variables: ", join(", ", @missing), "\n";
    exit;
  }
  return @found;
}