Skip to content

Commit abbed64

Browse files
authored
Publish airgapped image using stripped down preview server (#3264)
* Publish airgapped image using stripped down preview server * update scripts * move test port back to 8000 * uncomment again * isolate air_gapped build scripts * ensure preview/build.sh is still called * ?? null coelescing does not work on older nodejs versions
1 parent ca3951e commit abbed64

File tree

7 files changed

+30
-49
lines changed

7 files changed

+30
-49
lines changed

air_gapped/Dockerfile

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,14 @@
1-
FROM docker.elastic.co/docs/preview:latest AS build
1+
FROM cgr.dev/chainguard/wolfi-base
22

3-
COPY air_gapped/work/target_repo.git /docs_build/.repos/target_repo.git
4-
5-
FROM chainguard/wolfi-base:latest
6-
#FROM perl:5.42-bookworm
7-
RUN apk update
8-
RUN apk add perl
9-
RUN apk add curl
10-
RUN apk add perl-app-cpanminus
11-
12-
RUN apk add gcc make git patch perl-dev wget
13-
RUN apk add openssl-dev
14-
RUN apk add zlib-dev
15-
RUN apk add perl-net-ssleay
16-
17-
ENV PERL5LIB=/usr/local/lib/perl5
18-
ENV PATH=/usr/local/bin:$PATH
3+
RUN apk update && apk add nodejs git npm
194

20-
WORKDIR /
21-
RUN cpanm -n XML::LibXML
22-
RUN cpanm -n File::Copy::Recursive
23-
RUN cpanm -n Path::Class
24-
RUN cpanm -n Parallel::ForkManager
25-
RUN cpanm -n YAML
26-
#RUN apt update -y
27-
#RUN apt-get install -y perl
28-
#RUN apt-get install -y nginx
29-
#RUN apt-get install -y nodejs
30-
#RUN apt-get install -y git
31-
32-
#RUN apt-get install -y libxml-simple-perl
33-
#RUN apt-get install -y libfile-copy-recursive-perl
34-
#RUN apt-get install -y libpath-class-perl
35-
#RUN apt-get install -y libcapture-tiny-perl
36-
#RUN apt-get install -y libparallel-forkmanager-perl
37-
#RUN apt-get install -y libyaml-perl
38-
39-
RUN apk add nginx
40-
RUN apk add nodejs
41-
42-
COPY --from=build /docs_build /docs_build
43-
COPY --from=build /node_modules /node_modules
5+
WORKDIR /app
6+
COPY air_gapped/work/target_repo.git /docs_build/.repos/target_repo.git
7+
COPY --chown=node:node preview /app/preview/
8+
COPY --chown=node:node template /app/template/
9+
COPY --chown=node:node preview/package.json /app/package.json
10+
WORKDIR /app
11+
RUN npm install
4412

45-
RUN adduser -D nginx
46-
RUN mkdir -p /var/lib/nginx/tmp/
13+
ENTRYPOINT ["node", "preview/cli.js", "git", "/docs_build/.repos/target_repo.git"]
4714

48-
CMD ["/docs_build/build_docs.pl", "--in_standard_docker", "--gapped", "--preview"]

air_gapped/Dockerfile.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
*
22
!air_gapped
3+
!preview
4+
!template

air_gapped/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mkdir air_gapped/work
1919
git clone --reference ~/.git-references/built-docs.git --dissociate \
2020
--depth 2 --branch master --bare \
2121
git@github.com:elastic/built-docs.git air_gapped/work/target_repo.git
22+
2223
GIT_DIR=air_gapped/work/target_repo.git git fetch
2324

2425
# Build the images

air_gapped/build_bk.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ mkdir air_gapped/work
1515
git clone --reference /opt/git-mirrors/built-docs.git --dissociate \
1616
--depth 2 --branch master --bare \
1717
git@github.com:elastic/built-docs.git air_gapped/work/target_repo.git
18+
1819
GIT_DIR=air_gapped/work/target_repo.git git fetch
1920

2021
# Build the images

air_gapped/test.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ set -e
1010
cd $(git rev-parse --show-toplevel)
1111

1212
source ./air_gapped/build.sh
13-
id=$(docker run --rm \
14-
--publish 8000:8000/tcp \
15-
-d \
16-
$AIR_GAPPED)
13+
id=$(docker run --rm --publish 8000:8000/tcp -d $AIR_GAPPED)
14+
1715
echo "Started the air gapped docs. Some useful commands:"
1816
echo " docker kill $id"
1917
echo " docker logs -tf $id"

preview/package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"license": "SEE LICENSE IN README.asciidoc",
3+
"dependencies": {
4+
"yargs": "^14.0.0",
5+
"dedent": "^0.7.0",
6+
"recursive-copy": "^2.0.10"
7+
}
8+
}

preview/preview.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ const checkRedirects = async (core, path) => {
188188

189189
module.exports = Core => {
190190
const server = http.createServer((request, response) => {
191-
const parsedUrl = url.parse(request.url);
191+
let host = process.env.HOST;
192+
if (host == null || host === "") {
193+
host = "localhost";
194+
}
195+
196+
const parsedUrl = new URL(`http://${host}${request.url}`);
192197
const prefix = hostPrefix(request.headers['host']);
193198
const core = Core(prefix);
194199
requestHandler(core, parsedUrl, response)

0 commit comments

Comments
 (0)