Skip to content

Commit

Permalink
[ADP-3368] Add docker steps to main pipeline (#4666)
Browse files Browse the repository at this point in the history
- [x] Add docker build image step to main pipeline for all pushes
- [x] Add docker compose smoke test and docker push steps for release
candidate push

ADP-3368
  • Loading branch information
paolino authored Jul 7, 2024
2 parents 4bb3276 + d57ca17 commit 8aaa551
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 22 deletions.
8 changes: 4 additions & 4 deletions .buildkite/docker-build-push.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ in
# Apply tagging scheme
orig_tag="${image.imageName}:${image.imageTag}"
git_branch="''${BUILDKITE_BRANCH:-}"
git_tag="''${BUILDKITE_TAG:-}"
git_branch="''${BUILDKITE_BRANCH:-}"
tags=()
if [[ "$git_tag" =~ ^v20 ]]; then
tags+=( "${image.imageTag}" )
tags+=( "latest" )
elif [[ "$git_tag" = "rc-latest" ]]; then
tags+=( "$git_tag")
elif [[ "$git_branch" =~ ^release-candidate ]]; then
tags+=( "release-candidate" )
else
echo 'Not pushing docker image because this is neither a rc-latest nor a v20* tag build.'
tags+=( "test")
fi
echo
Expand Down
70 changes: 52 additions & 18 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ steps:
export BENCHMARK_CSV_FILE="`pwd`/bench-results.csv"
./scripts/buildkite/main/bench-latency.sh
depends_on: trigger-benchmarks
timeout_in_minutes: 20
timeout_in_minutes: 30
agents:
system: x86_64-linux
queue: adrestia-bench
Expand Down Expand Up @@ -431,20 +431,54 @@ steps:
agents:
system: ${linux}

- wait: ~

- block: Push Docker Image
if: build.env("RELEASE_CANDIDATE") == null
key: docker-push-block

- label: Push Docker Image
depends_on:
- linux-nix
- docker-push-block
key: build-docker
command:
- "mkdir -p config && echo '{ outputs = _: { dockerHubRepoName = \"cardanofoundation/cardano-wallet\"; }; }' > config/flake.nix"
- "nix build .#pushDockerImage --override-input hostNixpkgs \"path:$(nix eval --impure -I $NIX_PATH --expr '(import <nixpkgs> {}).path')\" --override-input customConfig path:./config -o docker-build-push"
- "./docker-build-push"
agents:
system: x86_64-linux
- group: Docker Artifacts
key: docker-artifacts
steps:
- block: Build Docker Artifacts
if: |
build.branch !~ /^gh-readonly-queue\/master/
&& build.branch != "master"
&& build.env("RELEASE_CANDIDATE") == null
key: docker-artifacts-block

- label: Build Docker Image
key: docker-build
depends_on:
- docker-artifacts-block
- linux-nix
commands:
./scripts/buildkite/release/docker-build.sh
agents:
system: x86_64-linux

- label: Push Docker Image
if: build.env("RELEASE_CANDIDATE") != null
depends_on:
- linux-nix
- docker-build
- docker-smoke-test
key: build-docker
command:
- "mkdir -p config && echo '{ outputs = _: { dockerHubRepoName = \"cardanofoundation/cardano-wallet\"; }; }' > config/flake.nix"
- "nix build .#pushDockerImage --override-input hostNixpkgs \"path:$(nix eval --impure -I $NIX_PATH --expr '(import <nixpkgs> {}).path')\" --override-input customConfig path:./config -o docker-build-push"
- "./docker-build-push"
agents:
system: x86_64-linux

- group: Docker Checks
key: docker-e2e
steps:
- label: Smoke Test docker-compose
if: build.env("RELEASE_CANDIDATE") != null
key: docker-smoke-test
depends_on:
- docker-build
timeout_in_minutes: 120
commands:
- ./scripts/buildkite/release/docker-smoke-test.sh
artifact_paths:
- "./logs/*"
env:
NODE_STATE_DIR: "${STATE_DIR?}/node/preprod"
agents:
system: x86_64-linux
16 changes: 16 additions & 0 deletions scripts/buildkite/release/docker-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env -S nix shell --command bash
# shellcheck shell=bash

set -euox pipefail

git fetch --all

RELEASE_CANDIDATE_COMMIT=$(buildkite-agent meta-data get "release-candidate-commit" --default="${BUILDKITE_COMMIT}")

git checkout "$RELEASE_CANDIDATE_COMMIT"

mkdir -p result

nix build .#dockerImage -o result/docker-image

docker load < result/docker-image
78 changes: 78 additions & 0 deletions scripts/buildkite/release/docker-smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#! /usr/bin/env -S nix shell 'nixpkgs#docker-compose' 'nixpkgs#rsync' 'nixpkgs#jq' --command bash
# shellcheck shell=bash

set -euox pipefail


NETWORK=preprod
export NETWORK

TESTS_NODE_DB="$(pwd)/state/node_db"

mkdir -p "$TESTS_NODE_DB"
export TESTS_NODE_DB

rsync -a --delete "$NODE_STATE_DIR/db/" "$TESTS_NODE_DB"

WALLET_TAG=$(buildkite-agent meta-data get "release-cabal-version")
export WALLET_TAG

NODE_TAG="8.9.4"
export NODE_TAG

NODE_DB="$TESTS_NODE_DB"
export NODE_DB

WALLET_DB="$(pwd)/state/wallet_db"
mkdir -p "$WALLET_DB"
export WALLET_DB

WALLET_PORT=$(shuf -i 2000-65000 -n 1)
export WALLET_PORT

USER_ID=$(id -u)
export USER_ID

tmpfile=$(mktemp -d /tmp/node-preprod.XXXXXX)

# set the node socket path
NODE_SOCKET_DIR="$tmpfile"
export NODE_SOCKET_DIR

NODE_SOCKET_NAME="node.socket"
export NODE_SOCKET_NAME

COMPOSE_PROJECT_NAME="docker-smoke-test-$WALLET_PORT"
export COMPOSE_PROJECT_NAME

docker compose down || true

docker-compose up -d

n=0
while :
do
result=$(curl --connect-timeout 1 localhost:"$WALLET_PORT"/v2/network/information || echo "wait")
echo "$result"
if [ "$result" != "wait" ];
then
echo "$result" | jq
break
else
sleep 30
n=$((n+1))
fi
done


mkdir -p logs
docker-compose logs > logs/docker-compose.log
docker-compose down

rm -rf "$tmpfile"

if [ "$result" == "wait" ];
then
echo "Failed to start the wallet server"
exit 1
fi

0 comments on commit 8aaa551

Please sign in to comment.