Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automate docker image push #4937

Merged
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
112 changes: 0 additions & 112 deletions .buildkite/docker-build-push.nix

This file was deleted.

16 changes: 0 additions & 16 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -625,22 +625,6 @@ steps:
agents:
system: x86_64-linux

- block: Docker Build
depends_on: []
if: build.env("TEST_RC") == "TRUE"
key: docker-build-block

- label: Push Docker Image
depends_on:
- docker-build
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
depends_on:
- docker-artifacts
Expand Down
43 changes: 36 additions & 7 deletions .buildkite/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ steps:
RELEASE: false
agents:
system: x86_64-linux
concurrency: 1
concurrency_group: push-swagger-nightly-or-test

- label: Push nightly or test release tag
key: push-nightly-or-test-tag
Expand All @@ -66,6 +68,8 @@ steps:
system: x86_64-linux
env:
RELEASE: false
concurrency: 1
concurrency_group: push-release-nightly-or-test

- label: Push nightly or test release artifacts
depends_on: push-nightly-or-test-release
Expand All @@ -75,6 +79,18 @@ steps:
system: x86_64-linux
env:
RELEASE: false
concurrency: 1
concurrency_group: push-release-nightly-or-test

- label: Push image to dockerhub
commands:
- nix develop path:$RELEASE_SCRIPTS_DIR -c $RELEASE_SCRIPTS_DIR/push-to-dockerhub.sh
agents:
system: x86_64-linux
env:
RELEASE: false
concurrency: 1
concurrency_group: push-dockerhub-nightly-or-test

- group: Release
depends_on: nightly-or-test
Expand All @@ -93,6 +109,8 @@ steps:
RELEASE: true
agents:
system: x86_64-linux
concurrency: 1
concurrency_group: push-swagger-release

- label: Push release tag
key: push-release-tag
Expand All @@ -113,6 +131,8 @@ steps:
system: x86_64-linux
env:
RELEASE: true
concurrency: 1
concurrency_group: push-release-release

- label: Push release artifacts
depends_on: push-release
Expand All @@ -122,16 +142,25 @@ steps:
system: x86_64-linux
env:
RELEASE: true
concurrency: 1
concurrency_group: push-release-release

- label: Push Docker Image
depends_on:
- create-release
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"
- block: Push to dockerhub
key: push-dockerhub
depends_on: create-release

- label: Push to dockerhub
depends_on: push-dockerhub
artifact_paths:
- ./artifacts/*.tgz
commands:
- nix develop path:$RELEASE_SCRIPTS_DIR -c $RELEASE_SCRIPTS_DIR/push-to-dockerhub.sh
agents:
system: x86_64-linux
env:
RELEASE: true
concurrency: 1
concurrency_group: push-dockerhub-release

- label: Update Documentation Links
depends_on: create-release
Expand Down
6 changes: 1 addition & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,7 @@
// rec {
dockerImage =
mkDockerImage (mkPackages walletProject.projectCross.musl64);
pushDockerImage = import ./.buildkite/docker-build-push.nix {
hostPkgs = import hostNixpkgs { inherit system; };
inherit dockerImage;
inherit (config) dockerHubRepoName;
};

} // (lib.optionalAttrs buildPlatform.isLinux {
nixosTests = import ./nix/nixos/tests {
inherit pkgs;
Expand Down
54 changes: 54 additions & 0 deletions scripts/buildkite/release/push-to-dockerhub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bash

set -euox pipefail

TRIGGERED_BY=$(buildkite-agent meta-data get base-build)
NEW_GIT_TAG=$(buildkite-agent meta-data get release-version)
TEST_RC=$(buildkite-agent meta-data get test-rc)
CABAL_VERSION=$(buildkite-agent meta-data get release-cabal-version)

if [ "$RELEASE" == "false" ]; then
if [ "$TEST_RC" == "TRUE" ]; then
TAG="test"
else
TAG="nightly"
fi
else
TAG=$NEW_GIT_TAG
fi

main_build=$(curl -H "Authorization: Bearer $BUILDKITE_API_TOKEN" \
-X GET "https://api.buildkite.com/v2/builds" \
| jq ".[] | select(.meta_data.\"triggered-by\" == \"$TRIGGERED_BY\")" \
| jq .number)

mkdir -p artifacts

repo="cardanofoundation/cardano-wallet"

artifact() {
local artifact_name=$1
# shellcheck disable=SC2155
local artifact_value=$(curl -H "Authorization: Bearer $BUILDKITE_API_TOKEN" \
-X GET "https://api.buildkite.com/v2/organizations/cardano-foundation/pipelines/cardano-wallet/builds/$main_build/artifacts?per_page=100" \
| jq -r " [.[] | select(.filename == \"$artifact_name\")][0] \
| .download_url")
curl -H "Authorization: Bearer $BUILDKITE_API_TOKEN" -L \
-o "artifacts/$artifact_name" \
"$artifact_value"
docker login -u cfhal -p "$DOCKER_HUB_TOKEN"
docker load -i "artifacts/$artifact_name"
local image_name="$repo:$TAG"
if [ "$RELEASE" == "false" ]; then
local loaded_image_name="$repo:$CABAL_VERSION"
docker tag "$loaded_image_name" "$image_name"
docker push "$image_name"
else
local latest_image_name="$repo:latest"
docker push "$image_name"
docker tag "$image_name" "$latest_image_name"
docker push "$latest_image_name"
fi
}

artifact "cardano-wallet-$NEW_GIT_TAG-docker-image.tgz"