Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .buildkite/docker-build-push.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# This script will load nix-built docker images of cardano-wallet
# into the Docker daemon (must be running), and then push to the
# Docker Hub. Credentials for the hub must already be installed with
# "docker login".

{ walletPackages ? import ../default.nix {}
, pkgs ? walletPackages.pkgs

# Build system's Nixpkgs. We use this so that we have the same docker
# version as the docker daemon.
, hostPkgs ? import <nixpkgs> {}

# Dockerhub repository for image tagging.
, dockerHubRepoName ? null
}:

with hostPkgs;
with hostPkgs.lib;

let
images = map impureCreated [
walletPackages.dockerImage
];

# Override Docker image, setting its creation date to the current time rather than the unix epoch.
impureCreated = image: image.overrideAttrs (oldAttrs: { created = "now"; }) // { inherit (image) version; };

in
writeScript "docker-build-push" (''
#!${runtimeShell}

set -euo pipefail

export PATH=${lib.makeBinPath [ docker gnused ]}

${if dockerHubRepoName == null then ''
reponame=cardano-wallet
username="$(docker info | sed '/Username:/!d;s/.* //')"
fullrepo="$username/$reponame"
'' else ''
fullrepo="${dockerHubRepoName}"
''}

'' + concatMapStringsSep "\n" (image: ''
branch="''${BUILDKITE_BRANCH:-}"
tag="''${BUILDKITE_TAG:-}"
if [[ -n "$tag" ]] || [[ "$branch" = "rvl/923/docker" ]]; then
tag="${image.imageTag}"
elif [[ "$branch" = master ]]; then
tag="$(echo ${image.imageTag} | sed -e s/${image.version}/''${BUILDKITE_COMMIT:-dev}/)"
else
echo "Not pushing docker image because this is not a master branch or tag build."
exit 0
fi
echo "Loading ${image}"
tagged="$fullrepo:$tag"
docker load -i "${image}"
if [ "$tagged" != "${image.imageName}:${image.imageTag}" ]; then
docker tag "${image.imageName}:${image.imageTag}" "$tagged"
fi
docker push "$tagged"
'') images)
7 changes: 7 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ steps:
command: 'nix-shell --run "openapi-spec-validator --schema 2.0 specifications/api/swagger.yaml"'
agents:
system: x86_64-linux

- label: 'Docker Image'
command:
- "nix-build .buildkite/docker-build-push.nix --argstr dockerHubRepoName inputoutput/cardano-wallet -o docker-build-push"
- "./docker-build-push"
agents:
system: x86_64-linux
4 changes: 4 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ let
tests = collectComponents "tests" isCardanoWallet haskellPackages;
benchmarks = collectComponents "benchmarks" isCardanoWallet haskellPackages;

dockerImage = pkgs.callPackage ./nix/docker.nix {
inherit (self) cardano-wallet-jormungandr;
};

shell = haskellPackages.shellFor {
name = "cardano-wallet-shell";
packages = ps: with ps; [
Expand Down
55 changes: 55 additions & 0 deletions nix/docker.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
############################################################################
# Docker image builder
#
# To test it out, use:
#
# docker load -i $(nix-build -A dockerImage --no-out-link)
# docker run cardano-wallet-jormungandr
#
############################################################################

{ runtimeShell, writeScriptBin, runCommand, dockerTools

# The main contents of the image.
, cardano-wallet-jormungandr

# Other things to include in the image.
, glibcLocales, iana-etc, bashInteractive, coreutils, utillinux, iproute, iputils, curl, socat

# Used to generate the docker image names
, repoName ? "inputoutput/cardano-wallet"
}:

let
defaultPort = "8090";

startScript = writeScriptBin "start-cardano-wallet-jormungandr" ''
#!${runtimeShell}
set -euo pipefail
export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"
exec ${cardano-wallet-jormungandr}/bin/cardano-wallet-jormungandr "$@"
'';

# Layer of tools which aren't going to change much between versions.
baseImage = dockerTools.buildImage {
name = "${repoName}-env";
contents = [ iana-etc bashInteractive coreutils utillinux iproute iputils curl socat ];
};

in
dockerTools.buildImage {
name = repoName;
tag = "${cardano-wallet-jormungandr.version}-jormungandr";
fromImage = baseImage;
contents = [
cardano-wallet-jormungandr
startScript
];
config = {
EntryPoint = [ "start-cardano-wallet-jormungandr" ];
# Cmd = [ "--port" defaultPort ];
ExposedPorts = {
"${defaultPort}/tcp" = {}; # wallet api
};
};
} // { inherit (cardano-wallet-jormungandr) version; }
1 change: 0 additions & 1 deletion nix/package-jormungandr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ let
chmod -R +w $out
${setGitRev}
strip $out/bin/cardano-wallet-jormungandr
cp ${jormungandr}/bin/* $out/bin
'';

darwin = buildCommand [] ''
Expand Down