Skip to content

Commit ce9a12e

Browse files
committed
Move to npm CLI
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
1 parent 76f44a2 commit ce9a12e

File tree

6 files changed

+1935
-1329
lines changed

6 files changed

+1935
-1329
lines changed

hack/build.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ set -o pipefail # exit on pipe failure
1616

1717
trap 'err_report $LINENO' ERR
1818

19-
export KO_DOCKER_REPO="${KO_DOCKER_REPO:-kind.local}"
20-
2119
build_transform_jsonata_image || exit $?
2220

2321
build_integration_images || exit $?

hack/common.sh

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,25 @@ export TRANSFORM_JSONATA_IMAGE_WITH_TAG="${KO_DOCKER_REPO}/transform-jsonata:${T
1010
[[ ! -v REPO_ROOT_DIR ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
1111
readonly REPO_ROOT_DIR
1212

13-
function build_transform_jsonata_image() {
14-
15-
docker version
16-
docker buildx version
13+
export TRANSFORM_JSONATA_DIR="${REPO_ROOT_DIR}/transform-jsonata"
1714

18-
docker buildx build --debug \
19-
--platform "linux/amd64" \
20-
-t "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-amd64" \
21-
-f "${REPO_ROOT_DIR}/transform-jsonata/Dockerfile" \
22-
"${REPO_ROOT_DIR}/transform-jsonata" || return $?
15+
function build_transform_jsonata_image() {
2316

24-
docker buildx build --debug \
25-
--platform "linux/arm64" \
26-
-t "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-arm64" \
27-
-f "${REPO_ROOT_DIR}/transform-jsonata/Dockerfile" \
28-
"${REPO_ROOT_DIR}/transform-jsonata" || return $?
17+
download_pack_cli || return $?
18+
19+
cd "${TRANSFORM_JSONATA_DIR}" && \
20+
pack build "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-amd64" \
21+
--builder docker.io/heroku/builder:24 \
22+
--platform "linux/amd64" \
23+
--clear-cache && \
24+
cd -
25+
26+
cd "${TRANSFORM_JSONATA_DIR}" && \
27+
pack build "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-arm64" \
28+
--builder docker.io/heroku/builder:24 \
29+
--platform "linux/arm64" \
30+
--clear-cache && \
31+
cd -
2932
}
3033

3134
function push_transform_jsonata_image() {
@@ -50,3 +53,11 @@ function push_transform_jsonata_image() {
5053
function build_integration_images() {
5154
"${REPO_ROOT_DIR}/mvnw" clean package -P knative -DskipTests || return $?
5255
}
56+
57+
function download_pack_cli() {
58+
local dir
59+
dir="$(mktemp -d)"
60+
git clone --depth 1 --branch "v0.36.4" https://github.com/buildpacks/pack.git "${dir}"
61+
cd "${dir}" && go install ./cmd/pack && cd - || return $?
62+
rm -rf "${dir}"
63+
}

transform-jsonata/Dockerfile

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,32 @@
1-
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/nodejs-20 AS builder
2-
3-
ARG TARGETPLATFORM
1+
FROM registry.access.redhat.com/ubi9/nodejs-20 AS builder
42

53
# Set working directory
64
WORKDIR /app
75

8-
# Switch to non-root user
9-
USER 1001
10-
11-
# Install pnpm globally
12-
RUN npm install -g pnpm
6+
# Copy package.json and package-lock.json before installing dependencies
7+
# Ensure correct permissions by using --chown flag
8+
COPY --chown=1001:0 package.json package-lock.json ./
139

14-
# Copy package.json and pnpm-lock.yaml before installing dependencies
15-
COPY package.json pnpm-lock.yaml ./
16-
17-
# Install dependencies using pnpm
18-
RUN pnpm install --frozen-lockfile
10+
# Install dependencies as non-root user
11+
USER 1001
12+
RUN npm install --frozen-lockfile
1913

2014
# Copy the rest of the application files
21-
COPY . .
22-
23-
# Build the application (if necessary)
24-
RUN pnpm build || echo "No build step found, skipping"
15+
COPY --chown=1001:0 . .
2516

2617
# Use a minimal base image for runtime
27-
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/nodejs-20
28-
29-
ENV NODE_ENV=production
18+
FROM registry.access.redhat.com/ubi9/nodejs-20
3019

3120
# Set working directory
3221
WORKDIR /app
3322

23+
# Copy built files and dependencies
24+
COPY --from=builder --chown=1001:0 /app /app
25+
3426
# Switch to non-root user
3527
USER 1001
3628

37-
# Copy built files and dependencies
38-
COPY --from=builder /app /app
29+
ENV NODE_ENV=production
3930

4031
# Expose the application port
4132
EXPOSE 8080

transform-jsonata/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ broker <- trigger <- (response) <-
1515
Assuming current working directory is `transform-jsonata`
1616

1717
```shell
18-
pnpm dev
18+
npm dev
1919

20-
# or pnpm dev-kubevirt to inject a different example transformation
20+
# or npm dev-kubevirt to inject a different example transformation
2121
```
2222

2323
### Tracing
2424

2525
```shell
2626
docker run --rm -d -p 9411:9411 openzipkin/zipkin
2727

28-
pnpm dev-zipkin
28+
npm dev-zipkin
2929
```
3030

3131
## Building

0 commit comments

Comments
 (0)