#!/usr/bin/env bash # # This script builds and pushes windows Docker containers. Maintainers # can run this without pushing to a remote repo as long as DOCKER_LOGIN or # DOCKER_PASSWORD are not set. For pushing to personal repos # set those 2 env vars and update the *_IMAGE values below to point to your repos # # This script expects to be run from the repo root and has checks for running # from a Drone trigger. set -euxo pipefail # Environment variables used throughout this script. These must be set # otherwise bash will fail with an "unbound variable" error because of the `set # -u` flag on the above line. # # If the environment variables are unset, the variables below default to an # empty string. export TARGET_CONTAINER=${1:-} export DRONE_TAG=${DRONE_TAG:-} export DRONE_BRANCH=${DRONE_BRANCH:-} export DOCKER_LOGIN=${DOCKER_LOGIN:-} export DOCKER_PASSWORD=${DOCKER_PASSWORD:-} export AGENT_IMAGE=grafana/agent export AGENTCTL_IMAGE=grafana/agentctl if [ -n "$DRONE_TAG" ]; then VERSION=$DRONE_TAG else VERSION=$(./tools/image-tag) fi VERSION_TAG=$VERSION-windows # We also need to know which "branch tag" to update. Branch tags are used as a # secondary tag for Docker containers. The branch tag is "latest" when being # tagged from a stable release (i.e., not a release candidate) or the Drone # branch when coming from a Drone job. # # If we're not running from drone, we'll set the branch tag to match the # version. This effectively acts as a no-op because it will tag the same Docker # image twice. if [ -n "$DRONE_TAG" ] && [[ "$DRONE_TAG" != *"-rc."* ]]; then BRANCH_TAG=latest-windows elif [ -n "$DRONE_BRANCH" ]; then BRANCH_TAG=$DRONE_BRANCH-windows else BRANCH_TAG=$VERSION_TAG fi case "$TARGET_CONTAINER" in agent) docker build \ -t "$AGENT_IMAGE:$VERSION_TAG" \ -t "$AGENT_IMAGE:$BRANCH_TAG" \ --build-arg VERSION="$VERSION" \ --build-arg RELEASE_BUILD=1 \ -f ./cmd/grafana-agent/Dockerfile.windows \ . ;; agentctl) docker build \ -t "$AGENTCTL_IMAGE:$VERSION_TAG" \ -t "$AGENTCTL_IMAGE:$BRANCH_TAG" \ --build-arg VERSION="$VERSION" \ --build-arg RELEASE_BUILD=1 \ -f ./cmd/grafana-agentctl/Dockerfile.windows \ . ;; *) echo "Usage: $0 agent|agentctl" exit 1 ;; esac # Push images only if we have docker credentials and a drone tag is set if [ -n "$DOCKER_LOGIN" ] && [ -n "$DOCKER_PASSWORD" ]; then docker login -u "$DOCKER_LOGIN" -p "$DOCKER_PASSWORD" case "$TARGET_CONTAINER" in agent) docker push "$AGENT_IMAGE:$VERSION_TAG" docker push "$AGENT_IMAGE:$BRANCH_TAG" ;; agentctl) docker push "$AGENTCTL_IMAGE:$VERSION_TAG" docker push "$AGENTCTL_IMAGE:$BRANCH_TAG" ;; *) echo "Usage: $0 agent|agentctl" exit 1 ;; esac fi