Skip to content

Commit 6ffe0e0

Browse files
authored
docker/build: Improvements (#511)
- add rebuild script - improve user mapping - improve dockerfile - remove local context Signed-off-by: Ryan Northey <[email protected]>
1 parent 734f458 commit 6ffe0e0

5 files changed

Lines changed: 131 additions & 138 deletions

File tree

build-website.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
#!/bin/bash -e
1+
#!/usr/bin/env bash
22

3-
set -o pipefail
3+
set -e -o pipefail
44

55
BAZEL="${BAZEL:-bazel}"
66
OUTPUT_DIR="${1:-_site}"
7+
8+
if ! command -v "$BAZEL" &> /dev/null; then
9+
echo "bazel not found, exiting" >&2
10+
exit 1
11+
fi
12+
713
OUTPUT_BASE="$($BAZEL info output_base 2>/dev/null)"
814

915

docker-compose.yml

Lines changed: 81 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,106 @@
1+
# NOTE: you must `export UID` before building
2+
13
services:
2-
live:
4+
build:
35
build:
4-
context: docker
5-
dockerfile: Dockerfile
6-
ports:
7-
- 4000:4000
8-
command: bazel run //site:live
9-
volumes:
6+
context: &context https://github.com/envoyproxy/toolshed.git#f89fb5df8defa4b7daf9a19a899dbdfbbf3b8d62:docker/bazel
7+
args:
8+
USER_NAME: "${USER}"
9+
USER_ID: &uid "${UID}"
10+
GROUP_ID: &gid "${GID:-}"
11+
APT_PKGS: &apt_pkgs >-
12+
autoconf
13+
automake
14+
bison
15+
build-essential
16+
gawk
17+
git
18+
gnupg2
19+
libffi-dev
20+
libgdbm-dev
21+
libgmp-dev
22+
libncurses5-dev
23+
libreadline-dev
24+
libsqlite3-dev
25+
libssl-dev
26+
libtool
27+
libyaml-dev
28+
pkg-config
29+
sqlite3
30+
zlib1g-dev
31+
command: ./build-website.sh
32+
user: ${UID:-1000}:${GID:-}
33+
volumes: &volumes
1034
- .:/src/workspace/envoy-website
11-
- ~/.cache/bazel:/$HOME/.cache/bazel
12-
- ~/.cache/bazelisk:/$HOME/.cache/bazelisk
35+
- ~/.cache/bazel:$HOME/.cache/bazel
36+
- ~/.cache/bazelisk:$HOME/.cache/bazelisk
1337
working_dir: /src/workspace/envoy-website
1438
environment:
15-
LOCAL_UID: ${UID:?"`UID` must be set, try `export UID`"}
16-
LOCAL_USER_NAME: $USERNAME
17-
LOCAL_USER_HOME: $HOME
39+
BAZEL_BUILD_OPTIONS: &bazel_options ${BAZEL_BUILD_OPTIONS:-}
1840

19-
live_docs:
41+
live:
2042
build:
21-
context: docker
22-
dockerfile: Dockerfile
23-
ports:
24-
- 4000:4000
25-
command: |
26-
bash -c '\
27-
bazel run --action_env=ENVOY_COMMIT="$$(bazel run //docs:latest_version)" \
28-
//site:live_docs'
29-
volumes:
30-
- .:/src/workspace/envoy-website
31-
- ~/.cache/bazel:/$HOME/.cache/bazel
32-
- ~/.cache/bazelisk:/$HOME/.cache/bazelisk
43+
context: *context
44+
target: extra
45+
args:
46+
USER_NAME: ${USER}
47+
USER_ID: *uid
48+
GROUP_ID: *gid
49+
APT_PKGS: *apt_pkgs
50+
EXTRA_APT_PKGS: >-
51+
inotify-tools
52+
command: ./rebuild.sh
53+
user: ${UID:?"`UID` must be set, try `export UID`"}:${GID:-}
54+
volumes: *volumes
3355
working_dir: /src/workspace/envoy-website
3456
environment:
35-
LOCAL_UID: ${UID:?"`UID` must be set, try `export UID`"}
36-
LOCAL_USER_NAME: $USERNAME
37-
LOCAL_USER_HOME: $HOME
57+
BAZEL_BUILD_OPTIONS: *bazel_options
58+
DEBUG: ${DEBUG:-}
59+
RUN_ON_START: ${RUN_ON_START:-1}
60+
WATCH_COMMAND: inotify
3861

39-
build:
40-
build:
41-
context: docker
42-
dockerfile: Dockerfile
43-
command: ./build-website.sh
62+
website:
63+
image: nginx
64+
depends_on:
65+
- ${BUILDER:-build}
66+
command:
67+
- /bin/sh
68+
- -c
69+
- |
70+
cat <<EOF > /etc/nginx/conf.d/default.conf
71+
server {
72+
listen 8000;
73+
listen [::]:8000;
74+
server_name localhost;
75+
location / {
76+
root /usr/share/nginx/html;
77+
index index.html index.htm;
78+
}
79+
}
80+
EOF
81+
nginx -g 'daemon off;'
4482
volumes:
45-
- .:/src/workspace/envoy-website
46-
- ~/.cache/bazel:/$HOME/.cache/bazel
47-
- ~/.cache/bazelisk:/$HOME/.cache/bazelisk
48-
working_dir: /src/workspace/envoy-website
49-
environment:
50-
BAZEL_BUILD_OPTIONS: $BAZEL_BUILD_OPTIONS
51-
LOCAL_UID: ${UID:?"`UID` must be set, try `export UID`"}
52-
LOCAL_USER_NAME: $USERNAME
53-
LOCAL_USER_HOME: $HOME
83+
- ./_site:/usr/share/nginx/html:z
84+
ports:
85+
- 8000:8000
5486

5587
update:
5688
build:
5789
context: docker
5890
dockerfile: Dockerfile
91+
args:
92+
USER_NAME: "${USERNAME}"
93+
USER_ID: "${UID}"
94+
GROUP_ID: "${GID:-}"
5995
command: ./sync_envoy.sh
96+
user: "${UID:-1000}:${GID:-1000}"
6097
volumes:
6198
- .:/src/workspace/envoy-website
6299
- ${ENVOY_SRC_DIR:-../envoy}:/src/workspace/envoy
63100
- ~/.cache/bazel:/$HOME/.cache/bazel
64101
- ~/.cache/bazelisk:/$HOME/.cache/bazelisk
65102
working_dir: /src/workspace/envoy-website
66103
environment:
67-
LOCAL_UID: ${UID:?"`UID` must be set, try `export UID`"}
68-
LOCAL_USER_NAME: $USERNAME
69-
LOCAL_USER_HOME: $HOME
70104
ENVOY_SRC_DIR: ../envoy
71-
COMMITTER_NAME: ${COMMITTER_NAME}
72-
COMMITTER_EMAIL: ${COMMITTER_EMAIL}
73-
74-
static:
75-
image: nginx
76-
volumes:
77-
- ./_site:/usr/share/nginx/html:z
78-
ports:
79-
- 7000:80
105+
COMMITTER_NAME: ${COMMITTER_NAME:-}
106+
COMMITTER_EMAIL: ${COMMITTER_EMAIL:-}

docker/Dockerfile

Lines changed: 0 additions & 63 deletions
This file was deleted.

docker/entrypoint.sh

Lines changed: 0 additions & 19 deletions
This file was deleted.

rebuild.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/bin/bash -e
2+
3+
set -o pipefail
4+
5+
REBUILD_SCRIPT="https://raw.githubusercontent.com/envoyproxy/toolshed/refs/heads/main/sh/watch.sh"
6+
7+
8+
# X-platform implementaion of working `realpath`
9+
get_realpath() {
10+
if command -v realpath >/dev/null 2>&1; then
11+
realpath "$1" 2>/dev/null || echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
12+
else
13+
echo "$(cd "$(dirname "$1")" && pwd)/$(basename "$1")"
14+
fi
15+
}
16+
17+
18+
REBUILD="~/.cache/envoy-website/watch.sh)"
19+
CURRENT_DIR="$(get_realpath $(dirname "${BASH_SOURCE[0]}"))"
20+
BUILD_SCRIPT="${CURRENT_DIR}/build-website.sh"
21+
22+
23+
download_script () {
24+
if [[ -e "$REBUILD" ]]; then
25+
echo "Using cached watch.sh ($REBUILD)"
26+
return
27+
fi
28+
rebuild_dir="$(dirname "$REBUILD")"
29+
mkdir -p "$rebuild_dir"
30+
echo "Downloading: ${REBUILD_SCRIPT}"
31+
curl -sL "$REBUILD_SCRIPT" > "$REBUILD"
32+
chmod +x "$REBUILD"
33+
}
34+
35+
36+
rebuild () {
37+
download_script
38+
"$REBUILD" "${CURRENT_DIR}/site" "$BUILD_SCRIPT"
39+
}
40+
41+
42+
rebuild

0 commit comments

Comments
 (0)