Skip to content

Commit 3a85678

Browse files
ATC config overhaul, plus add Admin.Flip RPC.
* Split ATC's main.json into peers.json and services.json. * ATC can now read most configs from ZK or Etcd. * Add revision number argument to "atc reload". * Add "atcctl flip". * Also overhaul Docker build to use buildx and --platform. * Also fix bug in CertNames (zero value should allow any).
1 parent cfd75ae commit 3a85678

24 files changed

+860
-521
lines changed

.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.4.7
1+
0.4.8

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v0.4.8
2+
* Overhaul ATC configuration
3+
* Overhaul Docker build to use buildx and --platform
4+
* Bug fix: CertNames' zero value now defaults to "allow any" mode again
5+
16
v0.4.7
27
* API tweaks for mainutil and roxyresolver.Target
38
* Use structured errors in more places

Dockerfile

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# vim:set ft=dockerfile:
2-
ARG ARCH=amd64
3-
4-
FROM golang:1.16-alpine3.13 AS builder
52
ARG VERSION=unset
6-
ARG GOOS=linux
7-
ARG GOARCH=amd64
3+
ARG ARCH
4+
5+
FROM --platform=$BUILDPLATFORM golang:1.16-alpine3.13 AS builder
6+
ARG VERSION
7+
ARG TARGETPLATFORM
88
RUN ["apk", "add", "--no-cache", "libcap", "ca-certificates"]
99
RUN ["/bin/sh", "-c", "update-ca-certificates 2>/dev/null || true"]
1010
RUN ["/bin/sh", "-c", "echo 'hosts: files dns' > /etc/nsswitch.conf"]
@@ -13,7 +13,12 @@ COPY ./ ./
1313
RUN set -euo pipefail; \
1414
umask 022; \
1515
export LC_ALL=C TZ=Etc/UTC; \
16-
export GOPATH=/go GOOS=${GOOS} GOARCH=${GOARCH} CGO_ENABLED=0; \
16+
export GOPATH=/go CGO_ENABLED=0; \
17+
case "$TARGETPLATFORM" in \
18+
(linux/amd64) export GOOS=linux GOARCH=amd64 ;; \
19+
(linux/arm64v8) export GOOS=linux GOARCH=arm64 ;; \
20+
(*) echo "error: unknown platform $TARGETPLATFORM" >&1; exit 1;; \
21+
esac; \
1722
if [ "${VERSION}" = "unset" ]; then \
1823
cat .version > lib/mainutil/version.txt; \
1924
else \
@@ -42,12 +47,15 @@ RUN set -euo pipefail; \
4247
cp /build/dist/roxy.mime.json /opt/roxy/share/misc/roxy.mime.json.example; \
4348
cp /build/dist/roxy.mime.json /etc/opt/roxy/mime.json.example; \
4449
cp /build/dist/roxy.mime.json /etc/opt/roxy/mime.json; \
45-
cp /build/dist/atc.config.json /opt/roxy/share/misc/atc.config.json.example; \
46-
cp /build/dist/atc.config.json /etc/opt/atc/config.json.example; \
47-
cp /build/dist/atc.config.json /etc/opt/atc/config.json; \
48-
cp /build/dist/atc.main.json /opt/roxy/share/misc/atc.main.json.example; \
49-
cp /build/dist/atc.main.json /etc/opt/atc/main.json.example; \
50-
cp /build/dist/atc.main.json /etc/opt/atc/main.json; \
50+
cp /build/dist/atc.global.json /opt/roxy/share/misc/atc.global.json.example; \
51+
cp /build/dist/atc.global.json /etc/opt/atc/global.json.example; \
52+
cp /build/dist/atc.global.json /etc/opt/atc/global.json; \
53+
cp /build/dist/atc.peers.json /opt/roxy/share/misc/atc.peers.json.example; \
54+
cp /build/dist/atc.peers.json /etc/opt/atc/peers.json.example; \
55+
cp /build/dist/atc.peers.json /etc/opt/atc/peers.json; \
56+
cp /build/dist/atc.services.json /opt/roxy/share/misc/atc.services.json.example; \
57+
cp /build/dist/atc.services.json /etc/opt/atc/services.json.example; \
58+
cp /build/dist/atc.services.json /etc/opt/atc/services.json; \
5159
cp /build/dist/atc.cost.json /opt/roxy/share/misc/atc.cost.json.example; \
5260
cp /build/dist/atc.cost.json /etc/opt/atc/cost.json.example; \
5361
cp /build/dist/atc.cost.json /etc/opt/atc/cost.json; \
@@ -60,7 +68,7 @@ RUN set -euo pipefail; \
6068
chmod 0750 /var/opt/roxy/lib /var/opt/roxy/lib/acme /var/opt/roxy/lib/state; \
6169
chmod 2750 /var/opt/roxy/log
6270

63-
FROM ${ARCH}/alpine:3.13 AS final
71+
FROM --platform=$TARGETPLATFORM ${ARCH}/alpine:3.13 AS final
6472
COPY --from=builder /srv/ /srv/
6573
COPY --from=builder /etc/passwd /etc/group /etc/nsswitch.conf /etc/
6674
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

build_deb.sh

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,15 @@ build_for_os_arch() {
8989
cp dist/roxy.mime.json "${BUILDDIR}/opt/roxy/share/misc/roxy.mime.json.example"
9090
cp dist/roxy.mime.json "${BUILDDIR}/etc/opt/roxy/mime.json.example"
9191
cp dist/roxy.mime.json "${BUILDDIR}/etc/opt/roxy/mime.json"
92-
cp dist/atc.config.json "${BUILDDIR}/opt/roxy/share/misc/atc.config.json.example"
93-
cp dist/atc.config.json "${BUILDDIR}/etc/opt/atc/config.json.example"
94-
cp dist/atc.config.json "${BUILDDIR}/etc/opt/atc/config.json"
95-
cp dist/atc.main.json "${BUILDDIR}/opt/roxy/share/misc/atc.main.json.example"
96-
cp dist/atc.main.json "${BUILDDIR}/etc/opt/atc/main.json.example"
97-
cp dist/atc.main.json "${BUILDDIR}/etc/opt/atc/main.json"
92+
cp dist/atc.global.json "${BUILDDIR}/opt/roxy/share/misc/atc.global.json.example"
93+
cp dist/atc.global.json "${BUILDDIR}/etc/opt/atc/global.json.example"
94+
cp dist/atc.global.json "${BUILDDIR}/etc/opt/atc/global.json"
95+
cp dist/atc.peers.json "${BUILDDIR}/opt/roxy/share/misc/atc.peers.json.example"
96+
cp dist/atc.peers.json "${BUILDDIR}/etc/opt/atc/peers.json.example"
97+
cp dist/atc.peers.json "${BUILDDIR}/etc/opt/atc/peers.json"
98+
cp dist/atc.services.json "${BUILDDIR}/opt/roxy/share/misc/atc.services.json.example"
99+
cp dist/atc.services.json "${BUILDDIR}/etc/opt/atc/services.json.example"
100+
cp dist/atc.services.json "${BUILDDIR}/etc/opt/atc/services.json"
98101
cp dist/atc.cost.json "${BUILDDIR}/opt/roxy/share/misc/atc.cost.json.example"
99102
cp dist/atc.cost.json "${BUILDDIR}/etc/opt/atc/cost.json.example"
100103
cp dist/atc.cost.json "${BUILDDIR}/etc/opt/atc/cost.json"

build_docker.sh

Lines changed: 66 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export LC_ALL="C"
99
export TZ="Etc/UTC"
1010

1111
readonly PACKAGE="chronostachyon/roxy"
12+
readonly PLATFORM_LIST=( linux/amd64 linux/arm64v8 )
1213

1314
if [ "${RELEASE_MODE:-false}" = "true" ]; then
1415
FULL_VERSION="$GITHUB_REF"
@@ -30,68 +31,83 @@ else
3031
TAGS=( "$FULL_VERSION" "devel" )
3132
fi
3233

33-
OS_ARCH_LIST=( linux/amd64 linux/arm64 )
34-
35-
arch_from_goos_goarch() {
36-
local GOOS="$1"
37-
local GOARCH="$2"
38-
case "${GOOS}/${GOARCH}" in
39-
(linux/arm64)
40-
echo arm64v8
41-
;;
42-
(linux/*)
43-
echo "$GOARCH"
44-
;;
45-
(*)
46-
echo "error: ${GOOS}/${GOARCH} not implemented" >&2
47-
exit 1
48-
;;
49-
esac
34+
run() {
35+
echo "> $*"
36+
"$@" || return $?
5037
}
5138

52-
build_for_os_arch() {
53-
local goos="$1"
54-
local goarch="$2"
39+
build_for_platform() {
40+
local platform="$1"
41+
local platform_tag="${platform//\//-}"
42+
local arch="${platform#*/}"
43+
local -i rc=0
5544

56-
local dockerfile="Dockerfile"
57-
local arch="$(arch_from_goos_goarch "$goos" "$goarch")"
45+
declare -a args
5846

59-
declare -a flags
60-
flags=(
61-
--file="$dockerfile"
62-
--build-arg=GOOS="$goos"
63-
--build-arg=GOARCH="$goarch"
64-
--build-arg=ARCH="$arch"
65-
--build-arg=VERSION="$FULL_VERSION"
66-
)
67-
for tag in "${TAGS[@]}"; do
68-
flags=( "${flags[@]}" --tag="${PACKAGE}:${arch}-${tag}" )
69-
done
47+
run \
48+
docker buildx use "$platform_tag" \
49+
|| rc=$?
7050

71-
echo "> docker build ${flags[*]} ."
72-
docker build "${flags[@]}" .
51+
if [ $rc -ne 0 ]; then
52+
run \
53+
docker buildx create \
54+
--name="$platform_tag" \
55+
--driver="docker-container" \
56+
--platform="$platform" \
57+
--use
58+
fi
7359

74-
local tag
60+
args=( \
61+
docker \
62+
buildx \
63+
build \
64+
--file="Dockerfile" \
65+
--platform="$platform" \
66+
--build-arg=VERSION="$FULL_VERSION" \
67+
--build-arg=ARCH="$arch" \
68+
)
7569
for tag in "${TAGS[@]}"; do
76-
echo "> docker push ${PACKAGE}:${arch}-${tag}"
77-
docker push "${PACKAGE}:${arch}-${tag}"
70+
args=( \
71+
"${args[@]}" \
72+
--tag="${PACKAGE}:${platform_tag}-${tag}" \
73+
)
7874
done
75+
args=( \
76+
"${args[@]}" \
77+
--push \
78+
. \
79+
)
80+
81+
run "${args[@]}"
7982
}
8083

81-
for OS_ARCH in linux/amd64 linux/arm64; do
82-
GOOS="${OS_ARCH%/*}"
83-
GOARCH="${OS_ARCH#*/}"
84-
build_for_os_arch "$GOOS" "$GOARCH"
84+
for platform in "${PLATFORM_LIST[@]}"; do
85+
build_for_platform "$platform"
8586
done
8687

8788
for tag in "${TAGS[@]}"; do
88-
ARGS=( "${PACKAGE}:${tag}" )
89-
for OS_ARCH in linux/amd64 linux/arm64; do
90-
GOOS="${OS_ARCH%/*}"
91-
GOARCH="${OS_ARCH#*/}"
92-
ARCH="$(arch_from_goos_goarch "$GOOS" "$GOARCH")"
93-
ARGS=( "${ARGS[@]}" --amend "${PACKAGE}:${ARCH}-${tag}" )
89+
run \
90+
docker \
91+
manifest \
92+
rm \
93+
"${PACKAGE}:${tag}" \
94+
|| true
95+
96+
args=( \
97+
docker \
98+
manifest \
99+
create \
100+
"${PACKAGE}:${tag}" \
101+
)
102+
for platform in "${PLATFORM_LIST[@]}"; do
103+
platform_tag="${platform//\//-}"
104+
args=( "${args[@]}" "${PACKAGE}:${platform_tag}-${tag}" )
94105
done
95-
docker manifest create "${ARGS[@]}"
96-
docker manifest push "${PACKAGE}:${tag}"
106+
run "${args[@]}"
107+
108+
run \
109+
docker \
110+
manifest \
111+
push \
112+
"${PACKAGE}:${tag}"
97113
done

cmd/atc/admin.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import (
1212

1313
type AdminServer struct {
1414
roxy_v0.UnimplementedAdminServer
15+
16+
ref *Ref
1517
}
1618

17-
func (AdminServer) Ping(ctx context.Context, req *roxy_v0.PingRequest) (*roxy_v0.PingResponse, error) {
19+
func (s AdminServer) Ping(ctx context.Context, req *roxy_v0.PingRequest) (*roxy_v0.PingResponse, error) {
1820
log.Logger.Info().
1921
Str("rpcService", "roxy.v0.Admin").
2022
Str("rpcMethod", "Ping").
@@ -24,7 +26,7 @@ func (AdminServer) Ping(ctx context.Context, req *roxy_v0.PingRequest) (*roxy_v0
2426
return &roxy_v0.PingResponse{}, nil
2527
}
2628

27-
func (AdminServer) Reload(ctx context.Context, req *roxy_v0.ReloadRequest) (*roxy_v0.ReloadResponse, error) {
29+
func (s AdminServer) Reload(ctx context.Context, req *roxy_v0.ReloadRequest) (*roxy_v0.ReloadResponse, error) {
2830
log.Logger.Info().
2931
Str("rpcService", "roxy.v0.Admin").
3032
Str("rpcMethod", "Reload").
@@ -34,10 +36,27 @@ func (AdminServer) Reload(ctx context.Context, req *roxy_v0.ReloadRequest) (*rox
3436
if err := gMultiServer.Reload(); err != nil {
3537
return nil, status.Error(codes.Internal, err.Error())
3638
}
39+
40+
if err := s.ref.Load(ctx, req.Rev); err != nil {
41+
return nil, status.Error(codes.Internal, err.Error())
42+
}
43+
3744
return &roxy_v0.ReloadResponse{}, nil
3845
}
3946

40-
func (AdminServer) Shutdown(ctx context.Context, req *roxy_v0.ShutdownRequest) (*roxy_v0.ShutdownResponse, error) {
47+
func (s AdminServer) Flip(ctx context.Context, req *roxy_v0.FlipRequest) (*roxy_v0.FlipResponse, error) {
48+
log.Logger.Info().
49+
Str("rpcService", "roxy.v0.Admin").
50+
Str("rpcMethod", "Flip").
51+
Str("rpcInterface", "admin").
52+
Msg("RPC")
53+
54+
s.ref.Flip()
55+
56+
return &roxy_v0.FlipResponse{}, nil
57+
}
58+
59+
func (s AdminServer) Shutdown(ctx context.Context, req *roxy_v0.ShutdownRequest) (*roxy_v0.ShutdownResponse, error) {
4160
log.Logger.Info().
4261
Str("rpcService", "roxy.v0.Admin").
4362
Str("rpcMethod", "Shutdown").
@@ -50,7 +69,7 @@ func (AdminServer) Shutdown(ctx context.Context, req *roxy_v0.ShutdownRequest) (
5069
return &roxy_v0.ShutdownResponse{}, nil
5170
}
5271

53-
func (AdminServer) SetHealth(ctx context.Context, req *roxy_v0.SetHealthRequest) (*roxy_v0.SetHealthResponse, error) {
72+
func (s AdminServer) SetHealth(ctx context.Context, req *roxy_v0.SetHealthRequest) (*roxy_v0.SetHealthResponse, error) {
5473
log.Logger.Info().
5574
Str("rpcService", "roxy.v0.Admin").
5675
Str("rpcMethod", "SetHealth").

0 commit comments

Comments
 (0)