Skip to content

Commit 12ba717

Browse files
authored
compile the jarfile in docker (#2)
* compile the jarfile * trailing whitespace * derp * don't need this * keep the cron, nuke the test workflow taking too long to run in the GHA worker.
1 parent 39781de commit 12ba717

File tree

5 files changed

+38
-37
lines changed

5 files changed

+38
-37
lines changed

.github/workflows/make-test.yml

-17
This file was deleted.

Dockerfile

+22-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
1-
FROM alpine:3.20
2-
LABEL maintainer sndsgd
1+
FROM debian:trixie-slim AS build
2+
ARG VERSION
33

4-
ARG JARFILE_URL
4+
RUN apt-get update && apt-get install -y \
5+
build-essential curl gcc git gnupg nodejs openjdk-21-jdk-headless python3 zip
56

6-
RUN apk add --update --no-cache curl openjdk11-jre \
7-
&& curl ${JARFILE_URL} -o /opt/closure-compiler.jar \
8-
&& chmod 0755 /opt/closure-compiler.jar \
9-
&& echo -e "#!/bin/sh -e\nexec java -jar /opt/closure-compiler.jar \$@" > /usr/local/bin/closure-compiler \
10-
&& chmod +x /usr/local/bin/closure-compiler
7+
WORKDIR /opt
8+
RUN curl -fsSL https://github.com/bazelbuild/bazelisk/releases/download/v1.25.0/bazelisk-amd64.deb -o /tmp/bazelisk-amd64.deb \
9+
&& dpkg -i /tmp/bazelisk-amd64.deb
1110

12-
ENTRYPOINT ["/usr/local/bin/closure-compiler"]
11+
RUN git clone --depth=1 --branch ${VERSION} https://github.com/google/closure-compiler.git
12+
13+
WORKDIR /opt/closure-compiler
14+
15+
# use the tag from git (as opposed to ${VERSION}) to ensure we have the correct version
16+
RUN GIT_TAG=$(git describe --tags --abbrev=0) && \
17+
bazelisk build --define=COMPILER_VERSION=$GIT_TAG --verbose_failures //:compiler_uberjar_deploy.jar
18+
19+
# runtime image
20+
FROM debian:trixie-slim
21+
LABEL maintainer=sndsgd
22+
23+
RUN apt-get update && apt-get install --yes --no-install-recommends openjdk-21-jre-headless
24+
COPY --from=build /opt/closure-compiler/bazel-bin/compiler_uberjar_deploy.jar /opt/closure-compiler.jar
25+
ENTRYPOINT ["java", "-jar", "/opt/closure-compiler.jar"]

Makefile

+11-7
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@ help:
1616
| awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%s\033[0m~%s\n", $$1, $$2}' \
1717
| column -s "~" -t
1818

19-
VERSION_URL ?= https://repo1.maven.org/maven2/com/google/javascript/closure-compiler/
20-
VERSION_PATTERN ?= '(?<=>)[^/]+(?=/)'
19+
VERSION_URL ?= https://github.com/google/closure-compiler/tags
20+
VERSION_PATTERN ?= '/google/closure-compiler/releases/tag/v[0-9]+'
2121
.PHONY: ensure-version
2222
ensure-version:
2323
ifeq ($(VERSION),)
24-
$(info fetching latest version...)
25-
@$(eval VERSION = $(shell curl -s $(VERSION_URL) | grep '<a href="v' | sort | tail -n 1 | grep -Po $(VERSION_PATTERN)))
26-
@$(eval FETCHED_VERSION = $(VERSION))
24+
$(eval VERSION = $(shell curl -s $(VERSION_URL) | grep -Po $(VERSION_PATTERN) | head -n 1 | sed 's|.*/tag/||'))
25+
$(eval FETCHED_VERSION = $(VERSION))
2726
endif
28-
@$(eval JARFILE_URL := $(VERSION_URL)$(VERSION)/closure-compiler-$(VERSION).jar)
2927
@$(eval IMAGE := $(IMAGE_NAME):$(VERSION))
3028

3129
IMAGE_ARGS ?= --quiet
@@ -35,9 +33,15 @@ image: ensure-version
3533
$(info building image for closure compiler $(VERSION)...)
3634
@docker build \
3735
$(IMAGE_ARGS) \
38-
--build-arg JARFILE_URL=$(JARFILE_URL) \
36+
--build-arg VERSION=$(VERSION) \
3937
--tag $(IMAGE) \
4038
$(CWD)
39+
@VERSION_OUTPUT=$$(docker run --rm $(IMAGE) --version | grep "Version: " | awk '{print $$2}' | tr -d '[:space:]'); \
40+
if [ "$$VERSION_OUTPUT" != "$(VERSION)" ]; then \
41+
echo "unexpected version: '$$VERSION_OUTPUT' (expected: $(VERSION))"; \
42+
docker image rm $(IMAGE); \
43+
exit 1; \
44+
fi
4145
ifeq ($(VERSION),$(FETCHED_VERSION))
4246
@docker tag $(IMAGE) $(LATEST_IMAGE)
4347
endif

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ docker run --rm \
1515
-v "$(pwd)":"$(pwd)" \
1616
-w "$(pwd)" \
1717
ghcr.io/sndsgd/closure-compiler:latest \
18+
--compilation_level=ADVANCED \
19+
--language_out=ECMASCRIPT6_STRICT \
20+
--summary_detail_level=10 \
21+
--warning_level=VERBOSE \
1822
--js="$(pwd)/path/to/src/**.js" \
1923
--js="$(pwd)/path/to/entrypoint.js"
2024
```

tests/app.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,4 @@ console.log(lib.foobar(lib.foobar("--")));
55
console.log(lib.kilogramsToPounds(100));
66

77
document.body.appendChild(lib.createDiv("help"))
8-
document.body.appendChild(lib.createDiv("help1"))
9-
document.body.appendChild(lib.createDiv("help2"))
10-
document.body.appendChild(lib.createDiv("help3"))
11-
document.body.appendChild(lib.createDiv("help4", "foo"))
8+
document.body.appendChild(lib.createDiv("help", "pls"))

0 commit comments

Comments
 (0)