Skip to content

Commit 38b0792

Browse files
committed
fix(rootfs): use k8s env vars to find etcd
1 parent c30f8e5 commit 38b0792

7 files changed

Lines changed: 53 additions & 21 deletions

File tree

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
ifndef BUILD_TAG
2+
BUILD_TAG = git-$(shell git rev-parse --short HEAD)
3+
endif
14

25
COMPONENT = workflow
36
IMAGE = $(IMAGE_PREFIX)$(COMPONENT):$(BUILD_TAG)
@@ -9,9 +12,14 @@ check-docker:
912
exit 2; \
1013
fi
1114

12-
build: check-docker
15+
build: docker-build
16+
17+
docker-build: check-docker
1318
docker build --rm -t $(IMAGE) rootfs
1419

20+
docker-push:
21+
docker push ${IMAGE}
22+
1523
clean: check-docker
1624
docker rmi $(IMAGE)
1725

rootfs/Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
FROM alpine:3.2
22

33
# install common packages
4-
RUN apk add --update-cache curl bash sudo && rm -rf /var/cache/apk/*
5-
6-
# install etcdctl
7-
RUN curl -sSL -o /usr/local/bin/etcdctl https://s3-us-west-2.amazonaws.com/get-deis/etcdctl-v0.4.9 \
8-
&& chmod +x /usr/local/bin/etcdctl
9-
10-
# install confd
11-
RUN curl -sSL -o /usr/local/bin/confd https://github.com/kelseyhightower/confd/releases/download/v0.10.0/confd-0.10.0-linux-amd64 \
12-
&& chmod +x /usr/local/bin/confd
4+
RUN apk add --update-cache curl bash openssl sudo && rm -rf /var/cache/apk/*
5+
6+
# install etcdctl and confd
7+
RUN apk add --update-cache curl tar \
8+
&& curl -sSL https://github.com/coreos/etcd/releases/download/v2.2.1/etcd-v2.2.1-linux-amd64.tar.gz \
9+
| tar -vxz -C /usr/local/bin --strip=1 etcd-v2.2.1-linux-amd64/etcdctl \
10+
&& chown root:root /usr/local/bin/etcdctl \
11+
&& curl -sSL -o /usr/local/bin/confd https://github.com/kelseyhightower/confd/releases/download/v0.10.0/confd-0.10.0-linux-amd64 \
12+
&& chmod +x /usr/local/bin/confd \
13+
&& apk del --purge curl tar \
14+
&& rm -rf /var/cache/apk/*
1315

1416
# define execution environment
1517
CMD ["/app/bin/boot"]

rootfs/bin/boot

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ set -eo pipefail
88

99
# set debug based on envvar
1010
[[ $DEBUG ]] && set -x
11+
set -x
1112

1213
# configure etcd
13-
export ETCD_PORT=${ETCD_PORT:-4001}
14-
export ETCD="$HOST:$ETCD_PORT"
14+
export ETCD_PORT=${DEIS_ETCD_1_SERVICE_PORT_CLIENT:-4001}
15+
export ETCD_HOST=${DEIS_ETCD_1_SERVICE_HOST:-$HOST}
16+
export ETCD="$ETCD_HOST:$ETCD_PORT"
1517
export ETCD_PATH=${ETCD_PATH:-/deis/controller}
1618
export ETCD_TTL=${ETCD_TTL:-20}
1719

@@ -26,8 +28,7 @@ sleep $((ETCD_TTL+1))
2628

2729
function etcd_set_default {
2830
set +e
29-
ERROR="$(etcdctl --no-sync -C "$ETCD" mk "$ETCD_PATH/$1" "$2" >/dev/null 2>&1)"
30-
31+
ERROR="$(etcdctl --no-sync -C "$ETCD" mk "$ETCD_PATH/$1" "$2" 2>&1 >/dev/null)"
3132
if [[ $? -ne 0 ]] && echo "$ERROR" | grep -iqve "key already exists"; then
3233
echo "etcd_set_default: an etcd error occurred ($ERROR)"
3334
echo "aborting..."
@@ -38,7 +39,7 @@ function etcd_set_default {
3839

3940
function etcd_safe_mkdir {
4041
set +e
41-
ERROR="$(etcdctl --no-sync -C "$ETCD" mkdir "$1" >/dev/null 2>&1)"
42+
ERROR="$(etcdctl --no-sync -C "$ETCD" mkdir "$1" 2>&1 >/dev/null)"
4243

4344
if [[ $? -ne 0 ]] && echo "$ERROR" | grep -iqve "key already exists"; then
4445
echo "etcd_safe_mkdir: an etcd error occurred ($ERROR)"
@@ -61,6 +62,29 @@ etcd_safe_mkdir /deis/platform
6162
etcd_safe_mkdir /deis/scheduler
6263
etcd_safe_mkdir /deis/services
6364

65+
# HACK: set up keys for database
66+
etcd_safe_mkdir /deis/database
67+
ETCD_PATH=/deis/database etcd_set_default engine postgresql_psycopg2
68+
ETCD_PATH=/deis/database etcd_set_default name deis
69+
ETCD_PATH=/deis/database etcd_set_default user deis
70+
ETCD_PATH=/deis/database etcd_set_default password changeme123
71+
ETCD_PATH=/deis/database etcd_set_default host "${DEIS_DATABASE_SERVICE_HOST:-127.0.0.1}"
72+
ETCD_PATH=/deis/database etcd_set_default port "${DEIS_DATABASE_SERVICE_PORT:-5432}"
73+
74+
# HACK: set up keys for logs
75+
etcd_safe_mkdir /deis/logs
76+
# ETCD_PATH=/deis/logs etcd_set_default host "${DEIS_LOGS_SERVICE_HOST:-127.0.0.1}"
77+
78+
# HACK: set up keys for platform
79+
etcd_safe_mkdir /deis/platform
80+
ETCD_PATH=/deis/platform etcd_set_default domain localhost
81+
82+
# HACK: set up keys for registry
83+
etcd_safe_mkdir /deis/registry
84+
# ETCD_PATH=/deis/registry etcd_set_default protocol "${DEIS_REGISTRY_SERVICE_PROTOCOL:-http}"
85+
# ETCD_PATH=/deis/registry etcd_set_default host "${DEIS_REGISTRY_SERVICE_HOST:-127.0.0.1}"
86+
# ETCD_PATH=/deis/registry etcd_set_default port "${DEIS_REGISTRY_SERVICE_PORT:-5000}"
87+
6488
# run etcd data migrations
6589
echo "controller: running etcd data migrations..."
6690
for script in /app/migrations/data/*.sh;

rootfs/deis/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@
284284
TEST_RUNNER = 'api.tests.SilentDjangoTestSuiteRunner'
285285

286286
# etcd settings
287-
ETCD_HOST, ETCD_PORT = os.environ.get('ETCD', '127.0.0.1:4001').split(',')[0].split(':')
287+
ETCD_HOST = os.environ.get('DEIS_ETCD_1_SERVICE_HOST', '127.0.0.1')
288+
ETCD_PORT = os.environ.get('DEIS_ETCD_1_SERVICE_PORT_CLIENT', 4001)
288289

289290
# default deis settings
290291
LOG_LINES = 1000

rootfs/migrations/data/0001.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
ETCD_PORT=${ETCD_PORT:-4001}
4-
ETCD="$HOST:$ETCD_PORT"
53
ETCDCTL="etcdctl -C $ETCD"
64

75
if [[ "$($ETCDCTL get /deis/migrations/data/0001 2> /dev/null)" != "done" ]];

rootfs/migrations/data/0002.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#!/usr/bin/env bash
22

3-
ETCD_PORT=${ETCD_PORT:-4001}
4-
ETCD="$HOST:$ETCD_PORT"
53
ETCDCTL="etcdctl -C $ETCD"
64

75
# April 8, 2015: If registrationEnabled key exists, migrate it to registrationMode and delete it.

rootfs/templates/confd_settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
REGISTRY_PORT = '{{ getv "/deis/registry/port" }}'
3333

3434
# default to sqlite3, but allow postgresql config through envvars
35+
# 'ENGINE': 'django.db.backends.{{ getv "/deis/database/engine" }}',
3536
DATABASES = {
3637
'default': {
37-
'ENGINE': 'django.db.backends.{{ getv "/deis/database/engine" }}',
38+
'ENGINE': 'django.db.backends.postgresql_psycopg2',
3839
'NAME': '{{ getv "/deis/database/name" }}',
3940
'USER': '{{ getv "/deis/database/user" }}',
4041
'PASSWORD': '{{ getv "/deis/database/password" }}',

0 commit comments

Comments
 (0)