From cb4100412ab57966181f0dee6a33767affef6905 Mon Sep 17 00:00:00 2001 From: Luke Granger-Brown Date: Sun, 4 Oct 2020 02:34:09 +0100 Subject: [PATCH] gitlab-ci: add docker-images push --- .gitlab-ci.yml | 7 +++++++ docker-images.nix | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 docker-images.nix diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index cba0998efb..5ab3f851d1 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -38,3 +38,10 @@ kusakabe: extends: .deploy #resource_group: kusakabe script: './hack/deploy.sh "188.165.197.49" ""' + +docker-push: + stage: deploy + tags: + - deployer + script: + - 'bash -c "$(nix-build --no-out-link ./docker-images.nix)"' diff --git a/docker-images.nix b/docker-images.nix new file mode 100644 index 0000000000..68ae6b2fe9 --- /dev/null +++ b/docker-images.nix @@ -0,0 +1,29 @@ +# SPDX-FileCopyrightText: 2020 Luke Granger-Brown +# +# SPDX-License-Identifier: Apache-2.0 + +let + depot = (import ./default.nix {}); + pkgs = depot.third_party.nixpkgs; + lib = pkgs.lib; + images = { + "registry.apps.k8s.lukegb.tech/twitterchiver/archiver:latest" = depot.go.twitterchiver.archiver.dockerImage; + }; + + crane = "${depot.nix.pkgs.crane}/bin/crane"; + decompress = drv: pkgs.runCommandNoCC "docker-image" {} '' + ${pkgs.gzip}/bin/gunzip -c ${drv} > $out + ''; + pushCommands = lib.mapAttrsToList (name: value: '' + ${crane} push ${decompress value} ${name} + '') images; + + authCommands = lib.mapAttrsToList (name: value: '' + ${crane} auth login ${name} -u "${value.user}" -p "${value.password}" + '') depot.ops.secrets.deployer.dockerRegistryAuth; +in +pkgs.writeShellScript "push-images" '' + ${lib.concatStringsSep "\n" authCommands} + + ${lib.concatStringsSep "\n" pushCommands} +''