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

setup.sh: simplify #147

Merged
merged 42 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
59a6560
setup.sh: don't install software automatically
grahamc Jun 2, 2020
b912b6e
generate-envrc: make its own, trivial, shell script
grahamc Jun 2, 2020
8927d3e
setup.sh: drop cidr variable, unused
grahamc Jun 2, 2020
a004489
setup.sh: shellcheck SC2230: which is non-standard. Use builtin 'comm…
grahamc Jun 2, 2020
ae3c070
setup.sh: shellcheck SC2086: Double quote to prevent globbing and wor…
grahamc Jun 2, 2020
72f233c
setup.sh: shellcheck SC2181: Check exit code directly with e.g. 'if m…
grahamc Jun 2, 2020
6bfa17a
setup.sh: shellcheck sc1090/sc1091: don't follow sources
grahamc Jun 2, 2020
f2461fd
setup.sh: is_network_configured: clean up the logic ladder
grahamc Jun 2, 2020
4ec1a78
setup.sh: setup_networking: back out early if network is setup already
grahamc Jun 2, 2020
8f28f15
setup.sh: network: try less hard to configure the network
grahamc Jun 2, 2020
da08044
setup: pass system version to setup_network
grahamc Jun 2, 2020
45c295c
networking: stub out netplan support
grahamc Jun 2, 2020
f2bc924
networking: implement netplan further
grahamc Jun 2, 2020
3a03682
networking: centos: try harder to configure the networking (see: the …
grahamc Jun 2, 2020
8cc73e3
generate-envrc: emit a CIDR addr too
grahamc Jun 2, 2020
1f6434f
setup: configure network forwarding on ubuntu and centos
grahamc Jun 4, 2020
1496e60
setup: do per-distro branch in the network setup only
grahamc Jun 4, 2020
9e15085
setup: osie: move the webroot in to under deploy/
grahamc Jun 4, 2020
75f0429
setup: use env to find bash
grahamc Jun 5, 2020
cb03feb
setup: use DEPLOYDIR instead of recalculating / sharing $deploy
grahamc Jun 5, 2020
9a1077f
setup: use (..) to reduce scope leak between function calls
grahamc Jun 5, 2020
5abc4ea
setup: certs: generate once and not part of docker-compose
grahamc Jun 5, 2020
494e063
jq: add
grahamc Jun 5, 2020
be3e278
docker-compose: store the registry in the deploy dir
grahamc Jun 5, 2020
ec1c97c
generate-envrc: properly quote variables in the output
grahamc Jun 10, 2020
86abd9e
setup.sh: fixup jq expression in creating CSRs
grahamc Jun 10, 2020
f9c2174
setup.sh: docker-registry start: abstract mirroring images
grahamc Jun 10, 2020
d897d03
registry: add curl for healthchecks with a custom TLS cert
grahamc Jun 10, 2020
2a4c6af
check_containter_status: use healthcheck events
grahamc Jun 10, 2020
9d60e44
tinkerbell crt: only copy if it has changed; on error, ask the user t…
grahamc Jun 10, 2020
2bb0aaf
ubuntu 17.10 check: use jq instead of depending on bc
grahamc Jun 10, 2020
8bb6faf
setup network: only require ifup / ifdown if our network strategy req…
grahamc Jun 10, 2020
661f03b
tls certs: UID/GID -> id -g
grahamc Jun 10, 2020
c08db6c
setup: encourage the user to run docker-compose up on their own
grahamc Jun 10, 2020
3518507
run with -u
grahamc Jun 10, 2020
da3cc16
lsb_dist: tr in the function
grahamc Jun 10, 2020
4ff438d
Use DEPLOYDIR instead of pwd/deploy
grahamc Jun 10, 2020
5e1dec4
setup: put state in its own directory, away from the repo's contents
grahamc Jun 11, 2020
ffa901a
fluentbit config: mount read-only
grahamc Jun 11, 2020
eafab24
envrc: ditch BROADCAST, NETMASK calcualtion
grahamc Jun 12, 2020
08bbd9d
{generate-envrc,setup}.sh: handle incompatible terminals
grahamc Jun 12, 2020
df0d63a
setup: run the cert generation process each time
grahamc Jun 12, 2020
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
22 changes: 11 additions & 11 deletions deploy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
version: "2.1"
services:
certs:
build: tls
volumes:
- ./certs:/certs

tink-server:
image: quay.io/tinkerbell/tink:latest
restart: unless-stopped
Expand All @@ -31,7 +26,7 @@ services:
timeout: 2s
retries: 30
volumes:
- ./certs:/certs/${FACILITY}
- ./state/certs:/certs/${FACILITY}
logging:
driver: fluentd
options:
Expand Down Expand Up @@ -84,6 +79,11 @@ services:
REGISTRY_USERNAME: $TINKERBELL_REGISTRY_USERNAME
REGISTRY_PASSWORD: $TINKERBELL_REGISTRY_PASSWORD
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "curl --cacert /certs/ca.pem https://127.0.0.1"]
interval: 5s
timeout: 1s
retries: 5
environment:
REGISTRY_HTTP_ADDR: 0.0.0.0:443
REGISTRY_HTTP_TLS_CERTIFICATE: /certs/server.pem
Expand All @@ -92,8 +92,8 @@ services:
REGISTRY_AUTH_HTPASSWD_REALM: "Registry Realm"
REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd
volumes:
- ./certs:/certs
- /var/tinkerbell/registry:/var/lib/registry
- ./state/certs:/certs
- ./state/registry:/var/lib/registry
depends_on:
fluentbit:
condition: service_started
Expand Down Expand Up @@ -152,7 +152,7 @@ services:
ports:
- $TINKERBELL_NGINX_IP:80:80/tcp
volumes:
- /var/tinkerbell/nginx/:/usr/share/nginx/html/
- ./state/webroot:/usr/share/nginx/html/
logging:
driver: fluentd
options:
Expand Down Expand Up @@ -187,7 +187,7 @@ services:
depends_on:
- elasticsearch
volumes:
- ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf
- ./fluent-bit.conf:/fluent-bit/etc/fluent-bit.conf:ro

cacher:
image: quay.io/packet/cacher:workflow
Expand All @@ -207,7 +207,7 @@ services:
PGUSER: tinkerbell
ROLLBAR_TOKEN: ${ROLLBAR_TOKEN-ignored}
volumes:
- ./certs:/certs/${FACILITY}
- ./state/certs:/certs/${FACILITY}
logging:
driver: fluentd
options:
Expand Down
3 changes: 2 additions & 1 deletion deploy/registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
FROM registry:2
RUN apk add --no-cache --update curl
ARG REGISTRY_USERNAME
ARG REGISTRY_PASSWORD
RUN mkdir -p /certs /auth
RUN htpasswd -Bbn ${REGISTRY_USERNAME} ${REGISTRY_PASSWORD} > /auth/htpasswd
EXPOSE 443
EXPOSE 443
5 changes: 1 addition & 4 deletions deploy/tls/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

if [ -z "${TINKERBELL_TLS_CERT:-}" ]; then
(
FACILITY=$(echo "$FACILITY" | tr '[:upper:]' '[:lower:]')
echo "creating directory"
mkdir -p "certs"
FACILITY=$FACILITY sh gencerts.sh
rm server.csr server-csr.json
rm ca.csr ca.json
./gencerts.sh
)
fi

Expand Down
25 changes: 13 additions & 12 deletions deploy/tls/gencerts.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

if ! { [[ -r ca.json ]] && [[ -r ca.pem ]] && [[ -r ca-key.pem ]]; }; then
sed "s|@FACILITY@|$FACILITY|g" <ca.in.json >ca.json
set -eux

cd /certs

if [ ! -f ca-key.pem ]; then
cfssl gencert \
-initca ca.json | cfssljson -bare ca
rm -f server-csr.json server-*.pem
fi
if ! { [[ -r server-csr.json ]] && [[ -r server.pem ]] && [[ -r server-key.pem ]]; }; then
sed "s|@FACILITY@|$FACILITY|g" <server-csr.in.json >server-csr.json

if [ ! -f server.pem ]; then
cfssl gencert \
-ca=ca.pem \
-ca-key=ca-key.pem \
-config=ca-config.json \
-config=/ca-config.json \
-profile=server \
server-csr.json | cfssljson -bare server
cat server.pem ca.pem | tee bundle.pem
server-csr.json |
cfssljson -bare server
fi

cat server.pem ca.pem >bundle.pem.tmp

# only "modify" the file if truly necessary since workflow will serve it with
# modtime info for client caching purposes
cat server.pem ca.pem >bundle.pem.tmp
if ! cmp -s bundle.pem.tmp bundle.pem; then
mv bundle.pem.tmp bundle.pem
else
rm bundle.pem.tmp
fi

mv *.pem certs/
1 change: 0 additions & 1 deletion deploy/tls/server-csr.in.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"CN": "tinkerbell",
"hosts": [
"tinkerbell.@[email protected]",
"tinkerbell.registry",
"tinkerbell.tinkerbell",
"tinkerbell",
Expand Down
91 changes: 91 additions & 0 deletions generate-envrc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash

# stops the execution if a command or pipeline has an error
set -eu

if command -v tput >/dev/null && tput setaf 1 >/dev/null 2>&1; then
# color codes
RED="$(tput setaf 1)"
RESET="$(tput sgr0)"
fi

ERR="${RED:-}ERROR:${RESET:-}"

err() (
if [ -z "${1:-}" ]; then
cat >&2
else
echo "$ERR " "$@" >&2
fi
)

candidate_interfaces() (
ip -o link show |
awk -F': ' '{print $2}' |
sed 's/[ \t].*//;/^\(lo\|bond0\|\|\)$/d' |
sort
)

validate_tinkerbell_network_interface() (
local tink_interface=$1

if ! candidate_interfaces | grep -q "^$tink_interface$"; then
err "Invalid interface ($tink_interface) selected, must be one of:"
candidate_interfaces | err
return 1
else
return 0
fi
)

generate_password() (
head -c 12 /dev/urandom | sha256sum | cut -d' ' -f1
)

generate_envrc() (
local tink_interface=$1

validate_tinkerbell_network_interface "$tink_interface"

local registry_password
registry_password=$(generate_password)
cat <<EOF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can do cat <<-EOF to avoid indent changes. But for follow up PR is fine.

# Network interface for Tinkerbell's network
export TINKERBELL_NETWORK_INTERFACE="$tink_interface"

# Decide on a subnet for provisioning. Tinkerbell should "own" this
# network space. Its subnet should be just large enough to be able
# to provision your hardware.
export TINKERBELL_CIDR=29

# Host IP is used by provisioner to expose different services such as
# tink, boots, etc.
#
# The host IP should the first IP in the range, and the Nginx IP
# should be the second address.
export TINKERBELL_HOST_IP=192.168.1.1

# NGINX IP is used by provisioner to serve files required for iPXE boot
export TINKERBELL_NGINX_IP=192.168.1.2

# Docker Registry's username and password
export TINKERBELL_REGISTRY_USERNAME=admin
export TINKERBELL_REGISTRY_PASSWORD="$registry_password"

# Legacy options, to be deleted:
export FACILITY=onprem
export ROLLBAR_TOKEN=ignored
export ROLLBAR_DISABLE=1
EOF
)

main() (
if [ -z "${1:-}" ]; then
err "Usage: $0 network-interface-name > envrc"
exit 1
fi

generate_envrc "$1"
)

main "$@"
Loading