From c7dba02d17b068e576de7c155d5a5e58fa156a76 Mon Sep 17 00:00:00 2001 From: Noel Georgi Date: Tue, 12 Mar 2024 17:13:58 +0530 Subject: [PATCH] chore: run tailwindcss before creating image Run tailwindcss as part of build process. Signed-off-by: Noel Georgi --- .dockerignore | 5 +++- .github/workflows/ci.yaml | 4 +-- .kres.yaml | 56 +++++++++++++++++++++++++++++++++++++-- Dockerfile | 22 ++++++++++++--- Makefile | 18 ++++++++----- 5 files changed, 90 insertions(+), 15 deletions(-) diff --git a/.dockerignore b/.dockerignore index 6236734..89453eb 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2023-11-02T09:56:23Z by kres latest. +# Generated on 2024-03-12T11:43:50Z by kres latest. * !cmd @@ -12,3 +12,6 @@ !CHANGELOG.md !README.md !.markdownlint.json +!tailwind.config.js +!package.json +!package-lock.json diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 79c72fa..3826a8e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,6 +1,6 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-02-27T07:52:48Z by kres latest. +# Generated on 2024-03-12T11:43:50Z by kres latest. name: default concurrency: @@ -48,7 +48,7 @@ jobs: uses: docker/setup-buildx-action@v3 with: driver: remote - endpoint: tcp://localhost:1234 + endpoint: tcp://127.0.0.1:1234 timeout-minutes: 1 - name: base run: | diff --git a/.kres.yaml b/.kres.yaml index fe5283e..f1dda5f 100644 --- a/.kres.yaml +++ b/.kres.yaml @@ -17,6 +17,12 @@ name: image-image-factory spec: baseImage: alpine:3.18 additionalImages: [] + allowedLocalPaths: + - tailwind.config.js + - package.json + - package-lock.json + dependsOn: + - tailwind customCommands: - apk add --no-cache --update bash @@ -56,8 +62,8 @@ spec: toplevel: true - name: integration toplevel: true - inputs: - - base + - name: tailwind + toplevel: true --- kind: custom.Step name: integration.test @@ -118,3 +124,49 @@ spec: kind: service.CodeCov spec: targetThreshold: 10 # the actual coverage is much higher and reported from the integration test +--- +kind: custom.Step +name: tailwind +spec: + makefile: + enabled: true + phony: true + script: + - "@$(MAKE) local-tailwind-copy PUSH=false DEST=." + docker: + description: "Runs tailwind update" + enabled: true + stages: + - name: tailwind-base + description: "Installs tailwindcss" + from: docker.io/node:21.7.1-alpine3.19 + workdir: /src + steps: + - copy: + src: package.json package-lock.json + dst: . + - script: + cache: + - /src/node_modules + command: npm ci + - name: tailwind-update + description: "tailwind update" + from: tailwind-base + steps: + - copy: + src: tailwind.config.js + dst: . + - copy: + src: internal/frontend/http + dst: internal/frontend/http + - script: + cache: + - /src/node_modules + command: node_modules/.bin/tailwindcss -i internal/frontend/http/css/input.css -o internal/frontend/http/css/output.css --minify + - name: tailwind-copy + description: "Copies assets" + steps: + - copy: + from: tailwind-update + src: /src/internal/frontend/http/css/output.css + dst: internal/frontend/http/css/output.css diff --git a/Dockerfile b/Dockerfile index ac266bc..9a9b6e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,15 +1,15 @@ -# syntax = docker/dockerfile-upstream:1.6.0-labs +# syntax = docker/dockerfile-upstream:1.7.0-labs # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-02-27T07:52:48Z by kres latest. +# Generated on 2024-03-12T11:43:50Z by kres latest. ARG TOOLCHAIN FROM alpine:3.18 AS base-image-image-factory # runs markdownlint -FROM docker.io/node:21.6.2-alpine3.19 AS lint-markdown +FROM docker.io/node:21.7.1-alpine3.19 AS lint-markdown WORKDIR /src RUN npm i -g markdownlint-cli@0.39.0 RUN npm i sentences-per-line@0.2.1 @@ -18,6 +18,12 @@ COPY ./CHANGELOG.md ./CHANGELOG.md COPY ./README.md ./README.md RUN markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules node_modules/sentences-per-line/index.js . +# Installs tailwindcss +FROM docker.io/node:21.7.1-alpine3.19 AS tailwind-base +WORKDIR /src +COPY package.json package-lock.json . +RUN --mount=type=cache,target=/src/node_modules npm ci + # base toolchain image FROM ${TOOLCHAIN} AS toolchain RUN apk --update --no-cache add bash curl build-base protoc protobuf-dev @@ -47,6 +53,12 @@ ARG GOFUMPT_VERSION RUN go install mvdan.cc/gofumpt@${GOFUMPT_VERSION} \ && mv /go/bin/gofumpt /bin/gofumpt +# tailwind update +FROM tailwind-base AS tailwind-update +COPY tailwind.config.js . +COPY internal/frontend/http internal/frontend/http +RUN --mount=type=cache,target=/src/node_modules node_modules/.bin/tailwindcss -i internal/frontend/http/css/input.css -o internal/frontend/http/css/output.css --minify + # tools and sources FROM tools AS base WORKDIR /src @@ -68,6 +80,10 @@ RUN mkdir -p internal/version/data && \ echo -n ${SHA} > internal/version/data/sha && \ echo -n ${TAG} > internal/version/data/tag +# Copies assets +FROM scratch AS tailwind-copy +COPY --from=tailwind-update /src/internal/frontend/http/css/output.css internal/frontend/http/css/output.css + # builds the integration test binary FROM base AS integration-build RUN --mount=type=cache,target=/root/.cache/go-build --mount=type=cache,target=/go/pkg go test -c -covermode=atomic -coverpkg=./... -tags integration ./internal/integration diff --git a/Makefile b/Makefile index dfeaa98..1e4ad3f 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,11 @@ # THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT. # -# Generated on 2024-02-27T07:52:48Z by kres latest. +# Generated on 2024-03-12T11:43:50Z by kres latest. # common variables SHA := $(shell git describe --match=none --always --abbrev=8 --dirty) -TAG := $(shell git describe --tag --always --dirty) +TAG := $(shell git describe --tag --always --dirty --match v[0-9]\*) ABBREV_TAG := $(shell git describe --tags >/dev/null 2>/dev/null && git describe --tag --always --match v[0-9]\* --abbrev=0 || echo 'undefined') BRANCH := $(shell git rev-parse --abbrev-ref HEAD) ARTIFACTS := _out @@ -14,15 +14,15 @@ WITH_RACE ?= false REGISTRY ?= ghcr.io USERNAME ?= siderolabs REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME) -PROTOBUF_GO_VERSION ?= 1.32.0 +PROTOBUF_GO_VERSION ?= 1.33.0 GRPC_GO_VERSION ?= 1.3.0 GRPC_GATEWAY_VERSION ?= 2.19.1 VTPROTOBUF_VERSION ?= 0.6.0 DEEPCOPY_VERSION ?= v0.5.6 GOLANGCILINT_VERSION ?= v1.56.2 GOFUMPT_VERSION ?= v0.6.0 -GO_VERSION ?= 1.22.0 -GOIMPORTS_VERSION ?= v0.18.0 +GO_VERSION ?= 1.22.1 +GOIMPORTS_VERSION ?= v0.19.0 GO_BUILDFLAGS ?= GO_LDFLAGS ?= CGO_ENABLED ?= 0 @@ -133,7 +133,7 @@ else GO_LDFLAGS += -s endif -all: unit-tests image-factory image-image-factory integration.test integration lint +all: unit-tests image-factory image-image-factory integration.test integration tailwind lint .PHONY: clean clean: ## Cleans up all artifacts. @@ -209,7 +209,7 @@ lint-markdown: ## Runs markdownlint. lint: lint-golangci-lint lint-gofumpt lint-govulncheck lint-goimports lint-markdown ## Run all linters for the project. .PHONY: image-image-factory -image-image-factory: ## Builds image for image-factory. +image-image-factory: tailwind ## Builds image for image-factory. @$(MAKE) target-$@ TARGET_ARGS="--tag=$(REGISTRY)/$(USERNAME)/image-factory:$(TAG)" .PHONY: integration.test @@ -222,6 +222,10 @@ integration: integration.test docker pull $(REGISTRY)/$(USERNAME)/image-factory:$(TAG) docker run --rm --net=host --privileged -v /dev:/dev -v $(PWD)/$(ARTIFACTS)/integration.test:/bin/integration.test:ro --entrypoint /bin/integration.test $(REGISTRY)/$(USERNAME)/image-factory:$(TAG) -test.v $(TEST_FLAGS) -test.run $(RUN_TESTS) +.PHONY: tailwind +tailwind: + @$(MAKE) local-tailwind-copy PUSH=false DEST=. + .PHONY: rekres rekres: @docker pull $(KRES_IMAGE)