2016-06-03 00:25:58 +00:00
# Copyright 2016 The Kubernetes Authors.
2016-02-03 06:30:10 +00:00
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2016-01-05 08:52:12 +00:00
# Build the etcd image
#
# Usage:
2018-03-09 20:19:02 +00:00
# [TAGS=2.2.1 2.3.7 3.0.17 3.1.12] [REGISTRY=k8s.gcr.io] [ARCH=amd64] [BASEIMAGE=busybox] make (build|push)
2015-04-02 23:20:09 +00:00
2016-10-04 09:13:23 +00:00
# The image contains different etcd versions to simplify
# upgrades. Thus be careful when removing any tag from here.
#
# NOTE: The etcd upgrade rules are that you can upgrade only 1 minor
# version at a time, and patch release don't matter.
#
# Except from etcd-$(tag) and etcdctl-$(tag) binaries, we also
# need etcd and etcdctl binaries for backward compatibility reasons.
# That binary will be set to the last tag from $(TAGS).
2018-03-09 20:19:02 +00:00
TAGS ?= 2.2.1 2.3.7 3.0.17 3.1.12
REGISTRY_TAG ?= 3.1.12
2018-02-02 00:55:58 +00:00
# ROLLBACK_REGISTRY_TAG specified the tag that REGISTRY_TAG may be rolled back to.
2018-03-09 20:19:02 +00:00
ROLLBACK_REGISTRY_TAG ?= 3.1.12
2016-01-05 08:52:12 +00:00
ARCH ?= amd64
2018-03-09 20:19:02 +00:00
# Image should be pulled from k8s.gcr.io, which will auto-detect
# region (us, eu, asia, ...) and pull from the closest.
Switch to k8s.gcr.io vanity domain
This is the 2nd attempt. The previous was reverted while we figured out
the regional mirrors (oops).
New plan: k8s.gcr.io is a read-only facade that auto-detects your source
region (us, eu, or asia for now) and pulls from the closest. To publish
an image, push k8s-staging.gcr.io and it will be synced to the regionals
automatically (similar to today). For now the staging is an alias to
gcr.io/google_containers (the legacy URL).
When we move off of google-owned projects (working on it), then we just
do a one-time sync, and change the google-internal config, and nobody
outside should notice.
We can, in parallel, change the auto-sync into a manual sync - send a PR
to "promote" something from staging, and a bot activates it. Nice and
visible, easy to keep track of.
2018-01-17 19:36:53 +00:00
REGISTRY ?= k8s.gcr.io
2018-03-09 20:19:02 +00:00
# Images should be pushed to staging-k8s.gcr.io.
PUSH_REGISTRY ?= staging-k8s.gcr.io
2018-01-23 00:46:31 +00:00
# golang version should match the golang version from https://github.com/coreos/etcd/releases for REGISTRY_TAG version of etcd.
GOLANG_VERSION ?= 1.8.5
2017-01-27 18:04:24 +00:00
GOARM = 7
2016-01-05 08:52:12 +00:00
TEMP_DIR := $( shell mktemp -d)
2015-04-02 23:20:09 +00:00
2016-01-05 08:52:12 +00:00
i f e q ( $( ARCH ) , a m d 6 4 )
BASEIMAGE?= busybox
e n d i f
i f e q ( $( ARCH ) , a r m )
2017-08-14 14:30:27 +00:00
BASEIMAGE?= arm32v7/busybox
2016-04-14 04:29:10 +00:00
e n d i f
i f e q ( $( ARCH ) , a r m 6 4 )
2017-08-14 08:30:51 +00:00
BASEIMAGE?= arm64v8/busybox
2016-04-14 04:29:10 +00:00
e n d i f
i f e q ( $( ARCH ) , p p c 6 4 l e )
BASEIMAGE?= ppc64le/busybox
2016-01-05 08:52:12 +00:00
e n d i f
2016-11-18 13:52:21 +00:00
i f e q ( $( ARCH ) , s 3 9 0 x )
BASEIMAGE?= s390x/busybox
e n d i f
2015-04-02 23:20:09 +00:00
2016-01-05 08:52:12 +00:00
build :
2016-08-23 10:02:41 +00:00
# Copy the content in this dir to the temp dir,
# without copying the subdirectories.
2017-11-27 03:19:05 +00:00
find ./ -maxdepth 1 -type f | xargs -I { } cp { } $( TEMP_DIR)
2016-08-23 10:02:41 +00:00
2016-09-09 17:25:15 +00:00
# Compile attachlease
2018-02-02 00:55:58 +00:00
docker run --interactive -v $( shell pwd ) /../../../:/go/src/k8s.io/kubernetes -v $( TEMP_DIR) :/build -e GOARCH = $( ARCH) golang:$( GOLANG_VERSION) \
2016-09-09 17:25:15 +00:00
/bin/bash -c "CGO_ENABLED=0 go build -o /build/attachlease k8s.io/kubernetes/cluster/images/etcd/attachlease"
2016-10-10 11:20:50 +00:00
# Compile rollback
2018-02-02 00:55:58 +00:00
docker run --interactive -v $( shell pwd ) /../../../:/go/src/k8s.io/kubernetes -v $( TEMP_DIR) :/build -e GOARCH = $( ARCH) golang:$( GOLANG_VERSION) \
2016-10-10 11:20:50 +00:00
/bin/bash -c "CGO_ENABLED=0 go build -o /build/rollback k8s.io/kubernetes/cluster/images/etcd/rollback"
2016-04-14 04:29:10 +00:00
i f e q ( $( ARCH ) , a m d 6 4 )
# Do not compile if we should make an image for amd64, use the official etcd binaries instead
2016-10-04 09:13:23 +00:00
# For each release create a tmp dir 'etcd_release_tmp_dir' and unpack the release tar there.
for tag in $( TAGS) ; do \
etcd_release_tmp_dir = $( shell mktemp -d) ; \
curl -sSL --retry 5 https://github.com/coreos/etcd/releases/download/v$$ tag/etcd-v$$ tag-linux-amd64.tar.gz | tar -xz -C $$ etcd_release_tmp_dir --strip-components= 1; \
cp $$ etcd_release_tmp_dir/etcd $$ etcd_release_tmp_dir/etcdctl $( TEMP_DIR) /; \
cp $( TEMP_DIR) /etcd $( TEMP_DIR) /etcd-$$ tag; \
cp $( TEMP_DIR) /etcdctl $( TEMP_DIR) /etcdctl-$$ tag; \
done
2016-04-14 04:29:10 +00:00
e l s e
2016-10-10 20:42:29 +00:00
2016-04-14 04:29:10 +00:00
# Download etcd in a golang container and cross-compile it statically
2016-10-04 09:13:23 +00:00
# For each release create a tmp dir 'etcd_release_tmp_dir' and unpack the release tar there.
for tag in $( TAGS) ; do \
etcd_release_tmp_dir = $( shell mktemp -d) ; \
2018-03-09 20:19:02 +00:00
docker run --interactive -v $$ { etcd_release_tmp_dir} :/etcdbin golang:$( GOLANG_VERSION) /bin/bash -c \
2016-10-04 09:13:23 +00:00
" git clone https://github.com/coreos/etcd /go/src/github.com/coreos/etcd \
&& cd /go/src/github.com/coreos/etcd \
2018-03-09 20:19:02 +00:00
&& git checkout v$$ { tag} \
2016-10-04 09:13:23 +00:00
&& GOARM = $( GOARM) GOARCH = $( ARCH) ./build \
&& cp -f bin/$( ARCH) /etcd* bin/etcd* /etcdbin; echo 'done' " ; \
cp $$ etcd_release_tmp_dir/etcd $$ etcd_release_tmp_dir/etcdctl $( TEMP_DIR) /; \
cp $( TEMP_DIR) /etcd $( TEMP_DIR) /etcd-$$ tag; \
cp $( TEMP_DIR) /etcdctl $( TEMP_DIR) /etcdctl-$$ tag; \
done
2016-07-19 22:10:49 +00:00
# Add this ENV variable in order to workaround an unsupported arch blocker
# The multiarch feature is in an limited and experimental state right now, and etcd should work fine on arm64
# On arm (which is 32-bit), it can't handle >1GB data in-memory, but it is very unlikely someone tinkering with their limited arm devices would reach such a high usage
# ppc64le is still quite untested, but compiles and is probably in the process of being validated by IBM.
cd $( TEMP_DIR) && echo " ENV ETCD_UNSUPPORTED_ARCH= $( ARCH) " >> Dockerfile
2016-04-14 04:29:10 +00:00
e n d i f
2016-01-05 08:52:12 +00:00
# Replace BASEIMAGE with the real base image
2016-08-04 00:25:11 +00:00
cd $( TEMP_DIR) && sed -i.bak 's|BASEIMAGE|$(BASEIMAGE)|g' Dockerfile
2016-01-05 08:52:12 +00:00
# And build the image
2017-01-10 22:29:47 +00:00
docker build --pull -t $( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) $( TEMP_DIR)
2015-04-02 23:20:09 +00:00
2015-06-08 23:34:27 +00:00
push : build
2018-03-09 20:19:02 +00:00
docker tag $( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) $( PUSH_REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG)
docker push $( PUSH_REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG)
2016-01-05 08:52:12 +00:00
i f e q ( $( ARCH ) , a m d 6 4 )
2016-04-14 04:29:10 +00:00
# Backward compatibility. TODO: deprecate this image tag
2016-09-27 13:26:13 +00:00
docker tag $( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) $( REGISTRY) /etcd:$( REGISTRY_TAG)
2018-02-24 05:54:24 +00:00
docker push $( REGISTRY) /etcd:$( REGISTRY_TAG)
2016-01-05 08:52:12 +00:00
e n d i f
2015-04-02 23:20:09 +00:00
2018-02-02 00:55:58 +00:00
ETCD2_ROLLBACK_NEW_TAG = 3.0.17
ETCD2_ROLLBACK_OLD_TAG = 2.2.1
# Test a rollback to etcd2 from the earliest etcd3 version.
test-rollback-etcd2 :
mkdir -p $( TEMP_DIR) /rollback-etcd2
cd $( TEMP_DIR) /rollback-etcd2
@echo " Starting $( ETCD2_ROLLBACK_NEW_TAG) etcd and writing some sample data. "
docker run --tty --interactive -v $( TEMP_DIR) /rollback-etcd2:/var/etcd \
-e "TARGET_STORAGE=etcd3" \
-e " TARGET_VERSION= $( ETCD2_ROLLBACK_NEW_TAG) " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' INITIAL_CLUSTER = etcd-$$ ( hostname) = http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd3 START_VERSION = $( ETCD2_ROLLBACK_NEW_TAG) start_etcd && \
ETCDCTL_API = 3 /usr/local/bin/etcdctl-$( ETCD2_ROLLBACK_NEW_TAG) --endpoints http://127.0.0.1:$$ { ETCD_PORT} put /registry/k1 value1 && \
stop_etcd && \
[ $$ ( cat /var/etcd/data/version.txt) = $( ETCD2_ROLLBACK_NEW_TAG) /etcd3 ] '
@echo "Rolling back to the previous version of etcd and recording keyspace to a flat file."
docker run --tty --interactive -v $( TEMP_DIR) /rollback-etcd2:/var/etcd \
-e "TARGET_STORAGE=etcd2" \
-e " TARGET_VERSION= $( ETCD2_ROLLBACK_OLD_TAG) " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' INITIAL_CLUSTER = etcd-$$ ( hostname) = http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd2 START_VERSION = $( ETCD2_ROLLBACK_OLD_TAG) start_etcd && \
/usr/local/bin/etcdctl-$( ETCD2_ROLLBACK_OLD_TAG) --endpoint 127.0.0.1:$$ { ETCD_PORT} get /registry/k1 > /var/etcd/keyspace.txt && \
stop_etcd'
@echo " Checking if rollback successfully downgraded etcd to $( ETCD2_ROLLBACK_OLD_TAG) "
docker run --tty --interactive -v $( TEMP_DIR) /rollback-etcd2:/var/etcd \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' [ $$ ( cat /var/etcd/data/version.txt) = $( ETCD2_ROLLBACK_OLD_TAG) /etcd2 ] && \
grep -q value1 /var/etcd/keyspace.txt'
# Test a rollback from the latest version to the previous version.
test-rollback :
mkdir -p $( TEMP_DIR) /rollback-test
cd $( TEMP_DIR) /rollback-test
@echo " Starting $( REGISTRY_TAG) etcd and writing some sample data. "
docker run --tty --interactive -v $( TEMP_DIR) /rollback-test:/var/etcd \
-e "TARGET_STORAGE=etcd3" \
-e " TARGET_VERSION= $( REGISTRY_TAG) " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' INITIAL_CLUSTER = etcd-$$ ( hostname) = http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd3 START_VERSION = $( REGISTRY_TAG) start_etcd && \
ETCDCTL_API = 3 /usr/local/bin/etcdctl --endpoints http://127.0.0.1:$$ { ETCD_PORT} put /registry/k1 value1 && \
stop_etcd'
@echo "Rolling back to the previous version of etcd and recording keyspace to a flat file."
docker run --tty --interactive -v $( TEMP_DIR) /rollback-test:/var/etcd \
-e "TARGET_STORAGE=etcd3" \
-e " TARGET_VERSION= $( ROLLBACK_REGISTRY_TAG) " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' INITIAL_CLUSTER = etcd-$$ ( hostname) = http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd3 START_VERSION = $( ROLLBACK_REGISTRY_TAG) start_etcd && \
ETCDCTL_API = 3 /usr/local/bin/etcdctl --endpoints http://127.0.0.1:$$ { ETCD_PORT} get --prefix / > /var/etcd/keyspace.txt && \
stop_etcd'
@echo " Checking if rollback successfully downgraded etcd to $( ROLLBACK_REGISTRY_TAG) "
docker run --tty --interactive -v $( TEMP_DIR) /rollback-test:/var/etcd \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' [ $$ ( cat /var/etcd/data/version.txt) = $( ROLLBACK_REGISTRY_TAG) /etcd3 ] && \
grep -q value1 /var/etcd/keyspace.txt'
# Test migrating from each supported versions to the latest version.
test-migrate :
for tag in $( TAGS) ; do \
echo " Testing migration from $$ {tag} to $( REGISTRY_TAG) " && \
mkdir -p $( TEMP_DIR) /migrate-$$ { tag} && \
cd $( TEMP_DIR) /migrate-$$ { tag} && \
MAJOR_VERSION = $$ ( echo $$ { tag} | cut -c 1) && \
echo " Starting etcd $$ {tag} and writing sample data to keyspace " && \
docker run --tty --interactive -v $( TEMP_DIR) /migrate-$$ { tag} :/var/etcd \
-e " TARGET_STORAGE=etcd $$ {MAJOR_VERSION} " \
-e " TARGET_VERSION= $$ {tag} " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
" INITIAL_CLUSTER=etcd-\$ $( hostname) =http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd$$ { MAJOR_VERSION} START_VERSION = $$ { tag} start_etcd && \
if [ $$ { MAJOR_VERSION} = = 2 ] ; then \
/usr/local/bin/etcdctl --endpoint http://127.0.0.1:\$ ${ ETCD_PORT } set /registry/k1 value1; \
else \
ETCDCTL_API = 3 /usr/local/bin/etcdctl --endpoints http://127.0.0.1:\$ ${ ETCD_PORT } put /registry/k1 value1; \
fi && \
stop_etcd" && \
echo " Migrating from $$ {tag} to $( REGISTRY_TAG) and capturing keyspace " && \
docker run --tty --interactive -v $( TEMP_DIR) /migrate-$$ { tag} :/var/etcd \
-e "TARGET_STORAGE=etcd3" \
-e " TARGET_VERSION= $( REGISTRY_TAG) " \
-e "DATA_DIRECTORY=/var/etcd/data" \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' INITIAL_CLUSTER = etcd-$$ ( hostname) = http://localhost:2380 \
/usr/local/bin/migrate-if-needed.sh && \
source /usr/local/bin/start-stop-etcd.sh && \
START_STORAGE = etcd3 START_VERSION = $( REGISTRY_TAG) start_etcd && \
ETCDCTL_API = 3 /usr/local/bin/etcdctl --endpoints http://127.0.0.1:$$ { ETCD_PORT} get --prefix / > /var/etcd/keyspace.txt && \
stop_etcd' && \
echo " Checking if migrate from $$ {tag} successfully upgraded etcd to $( REGISTRY_TAG) " && \
docker run --tty --interactive -v $( TEMP_DIR) /migrate-$$ { tag} :/var/etcd \
2018-02-13 21:53:29 +00:00
$( REGISTRY) /etcd-$( ARCH) :$( REGISTRY_TAG) /bin/sh -c \
2018-02-02 00:55:58 +00:00
' [ $$ ( cat /var/etcd/data/version.txt) = $( REGISTRY_TAG) /etcd3 ] && \
grep -q value1 /var/etcd/keyspace.txt' ; \
done
test : test -rollback test -rollback -etcd 2 test -migrate
all : build test
.PHONY : build push test -rollback test -rollback -etcd 2 test -migrate test