diff --git a/Dockerfile b/Dockerfile new file mode 120000 index 0000000..08a84fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1 @@ +resolver-go/dockerfiles/api.Dockerfile \ No newline at end of file diff --git a/concourse/prepare-deployment-resources.yaml b/concourse/prepare-deployment-resources.yaml index 2eb6998..ab371da 100644 --- a/concourse/prepare-deployment-resources.yaml +++ b/concourse/prepare-deployment-resources.yaml @@ -18,6 +18,4 @@ run: - -exc - | VERSION=$( cat commit.sha ) - cat k8s/configmap.yaml >> deploy-confs/prod.yaml - echo -e "\n---\n" >> deploy-confs/prod.yaml sed "s/IMAGE_TAG/$VERSION/g" k8s/deployments.yaml >> deploy-confs/prod.yaml diff --git a/k8s/configmap.yaml b/k8s/configmap.yaml deleted file mode 100644 index 29ef51c..0000000 --- a/k8s/configmap.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: v1 -kind: ConfigMap -metadata: - name: astrojs-nginx-ctmpls - namespace: default -data: - default.conf.template: | - server { - listen 80; - listen [::]:80; - server_name localhost; - - expires 10d; - add_header Cache-Control "public"; - - location / { - root /usr/share/nginx/html; - index index.html index.htm; - } - - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; - } - } diff --git a/k8s/deployments.yaml b/k8s/deployments.yaml index 46b167a..24565da 100644 --- a/k8s/deployments.yaml +++ b/k8s/deployments.yaml @@ -22,56 +22,8 @@ spec: runAsNonRoot: true runAsUser: 1001 env: - - name: DEBUG - value: "0" - volumeMounts: - - name: cache - mountPath: "/app/cache" - livenessProbe: - exec: - command: - - sh - - -c - - wget -qO - http://127.0.0.1:5000/health - - name: redis - image: redis:6.0.8-alpine - - name: compiler - image: registry.k8s.astropenguin.net/closure-api:IMAGE_TAG - securityContext: - runAsNonRoot: true - env: - - name: DEBUG - value: "0" - volumeMounts: - - name: cache - mountPath: "/app/cache" - - name: assets - image: nginx:alpine - volumeMounts: - - mountPath: "/usr/share/nginx/html" - name: cache - - mountPath: "/etc/nginx/templates" - name: nginx-conf-templates - volumes: - - name: cache - persistentVolumeClaim: - claimName: astrojs-cache - - name: nginx-conf-templates - configMap: - name: astrojs-nginx-ctmpls - ---- - -apiVersion: v1 -kind: PersistentVolumeClaim -metadata: - name: astrojs-cache -spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: local-storage + - name: CLOSURE_ENDPOINT + value: "http://closure-api.default.svc.cluster.local/compile" --- @@ -83,9 +35,34 @@ spec: selector: app: astrojs ports: - - port: 5000 - targetPort: 5000 - name: application - - port: 80 - targetPort: 80 - name: files + - port: 8080 + targetPort: 8080 + name: web + +--- + +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: astrojs +spec: + parentRefs: + - name: gateway-prod + namespace: cilium-system + sectionName: k8s-astropenguin-net + hostnames: + - astrojs.k8s.astropenguin.net + rules: + - matches: + - path: + type: PathPrefix + value: / + filters: + - type: URLRewrite + urlRewrite: + path: + type: ReplaceFullPath + replaceFullPath: / + backendRefs: + - name: astrojs + port: 8080 diff --git a/k8s/ingress.yaml b/k8s/ingress.yaml deleted file mode 100644 index 1971d8c..0000000 --- a/k8s/ingress.yaml +++ /dev/null @@ -1,33 +0,0 @@ -apiVersion: networking.k8s.io/v1 -kind: Ingress -metadata: - name: default-astrojs - namespace: ingress-https -spec: - ingressClassName: nginx - tls: - - hosts: - - astrojs.k8s.astropenguin.net - secretName: any-k8s-astro-prod - rules: - - host: astrojs.k8s.astropenguin.net - http: - paths: - - path: / - pathType: Prefix - backend: - service: - name: default-astrojs - port: - number: 5000 - ---- - -kind: Service -apiVersion: v1 -metadata: - name: default-astrojs - namespace: ingress-https -spec: - type: ExternalName - externalName: astrojs.default.svc.cluster.local diff --git a/mk/resolver-go.mk b/mk/resolver-go.mk index 5d9c7b4..8881634 100644 --- a/mk/resolver-go.mk +++ b/mk/resolver-go.mk @@ -34,6 +34,12 @@ push-resolver: .buildinfo ensure-buildx resolver-gen -t $(RESOLVER_IMAGE_NAME):$(RESOLVER_IMAGE_TAG) \ --push . +run-api-server: + cd $(GO_SRC_DIR) && \ + go run ./cmd/classmap-gen -src "$(JS_SRC_DIR)" && \ + go run ./cmd/externs-gen -src "$(JS_SRC_DIR)" && \ + go run ./cmd/api-server -src "$(JS_SRC_DIR)" -addr :8080 + inspect-resolver: docker buildx imagetools inspect $(RESOLVER_IMAGE_NAME):$(RESOLVER_IMAGE_TAG) diff --git a/resolver-go/README.md b/resolver-go/README.md index d841690..6c46e95 100644 --- a/resolver-go/README.md +++ b/resolver-go/README.md @@ -10,9 +10,7 @@ Go rewrite for the old BotanJS dynamic resource resolver. ## Generate the class map ```sh -go run ./cmd/botan-gen \ - -src /path/to/BotanJS/src \ - -out internal/generated/classmap_gen.go +make resolver-gen ``` Commit the generated file if the source tree is mostly static. Generate it in CI if the source changes frequently. @@ -20,7 +18,7 @@ Commit the generated file if the source tree is mostly static. Generate it in CI ## Run API ```sh -go run ./cmd/botan-api -src /path/to/BotanJS/src -addr :8080 +make run-api-server ``` Examples: @@ -43,6 +41,4 @@ Prefix an item with `-` to exclude it. ## TODO -- Test against the old python resolver output -- Add an output interface so JS can be piped directly to a Closure Compiler server. -- Put generated classmap in a separate package if multiple services need to import it. +- Fix moderen closure errors diff --git a/resolver-go/botanjs b/resolver-go/botanjs new file mode 120000 index 0000000..30d1549 --- /dev/null +++ b/resolver-go/botanjs @@ -0,0 +1 @@ +../botanjs/ \ No newline at end of file diff --git a/resolver-go/cmd/botan-api/main.go b/resolver-go/cmd/api-server/main.go similarity index 100% rename from resolver-go/cmd/botan-api/main.go rename to resolver-go/cmd/api-server/main.go diff --git a/resolver-go/dockerfiles/api.Dockerfile b/resolver-go/dockerfiles/api.Dockerfile index e402d68..9548054 100644 --- a/resolver-go/dockerfiles/api.Dockerfile +++ b/resolver-go/dockerfiles/api.Dockerfile @@ -19,15 +19,15 @@ RUN --mount=type=cache,target=/go/pkg/mod \ CGO_ENABLED=0 \ GOOS=$TARGETOS \ GOARCH=$TARGETARCH \ - go build -trimpath -o /out/botan-api -ldflags='-s -w' ./cmd/botan-api + go build -trimpath -o /out/api-server -ldflags='-s -w' ./cmd/api-server RUN mkdir -p /out/tmp && chmod 1777 /out/tmp FROM scratch -COPY --from=build /out/botan-api /usr/local/bin/botan-api +COPY --from=build /out/api-server /usr/local/bin/api-server COPY --from=build /workspace/src "./src" COPY --from=build /out/tmp /tmp EXPOSE 8080/tcp -ENTRYPOINT ["/usr/local/bin/botan-api", "-src", "./src", "-addr", ":8080"] +ENTRYPOINT ["/usr/local/bin/api-server", "-src", "./src", "-addr", ":8080"] diff --git a/resolver-go/internal/generated/buildinfo_gen.go b/resolver-go/internal/generated/buildinfo_gen.go index 5246ed0..fc6b5e0 100644 --- a/resolver-go/internal/generated/buildinfo_gen.go +++ b/resolver-go/internal/generated/buildinfo_gen.go @@ -2,5 +2,5 @@ package generated const ( IMAGE_TAG = "dev" - Timestamp = "20260612.043857" + Timestamp = "20260612.044857" ) diff --git a/resolver-go/src b/resolver-go/src deleted file mode 120000 index c6a0283..0000000 --- a/resolver-go/src +++ /dev/null @@ -1 +0,0 @@ -../botanjs/src \ No newline at end of file