Skip to content

Commit

Permalink
Move to npm CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Pierangelo Di Pilato <pierdipi@redhat.com>
  • Loading branch information
pierDipi committed Feb 18, 2025
1 parent 76f44a2 commit ce9a12e
Show file tree
Hide file tree
Showing 6 changed files with 1,935 additions and 1,329 deletions.
2 changes: 0 additions & 2 deletions hack/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ set -o pipefail # exit on pipe failure

trap 'err_report $LINENO' ERR

export KO_DOCKER_REPO="${KO_DOCKER_REPO:-kind.local}"

build_transform_jsonata_image || exit $?

build_integration_images || exit $?
39 changes: 25 additions & 14 deletions hack/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ export TRANSFORM_JSONATA_IMAGE_WITH_TAG="${KO_DOCKER_REPO}/transform-jsonata:${T
[[ ! -v REPO_ROOT_DIR ]] && REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"
readonly REPO_ROOT_DIR

function build_transform_jsonata_image() {

docker version
docker buildx version
export TRANSFORM_JSONATA_DIR="${REPO_ROOT_DIR}/transform-jsonata"

docker buildx build --debug \
--platform "linux/amd64" \
-t "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-amd64" \
-f "${REPO_ROOT_DIR}/transform-jsonata/Dockerfile" \
"${REPO_ROOT_DIR}/transform-jsonata" || return $?
function build_transform_jsonata_image() {

docker buildx build --debug \
--platform "linux/arm64" \
-t "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-arm64" \
-f "${REPO_ROOT_DIR}/transform-jsonata/Dockerfile" \
"${REPO_ROOT_DIR}/transform-jsonata" || return $?
download_pack_cli || return $?

cd "${TRANSFORM_JSONATA_DIR}" && \
pack build "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-amd64" \
--builder docker.io/heroku/builder:24 \
--platform "linux/amd64" \
--clear-cache && \
cd -

cd "${TRANSFORM_JSONATA_DIR}" && \
pack build "${TRANSFORM_JSONATA_IMAGE_WITH_TAG}-arm64" \
--builder docker.io/heroku/builder:24 \
--platform "linux/arm64" \
--clear-cache && \
cd -
}

function push_transform_jsonata_image() {
Expand All @@ -50,3 +53,11 @@ function push_transform_jsonata_image() {
function build_integration_images() {
"${REPO_ROOT_DIR}/mvnw" clean package -P knative -DskipTests || return $?
}

function download_pack_cli() {
local dir
dir="$(mktemp -d)"
git clone --depth 1 --branch "v0.36.4" https://github.com/buildpacks/pack.git "${dir}"
cd "${dir}" && go install ./cmd/pack && cd - || return $?
rm -rf "${dir}"
}
35 changes: 13 additions & 22 deletions transform-jsonata/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,41 +1,32 @@
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/nodejs-20 AS builder

ARG TARGETPLATFORM
FROM registry.access.redhat.com/ubi9/nodejs-20 AS builder

# Set working directory
WORKDIR /app

# Switch to non-root user
USER 1001

# Install pnpm globally
RUN npm install -g pnpm
# Copy package.json and package-lock.json before installing dependencies
# Ensure correct permissions by using --chown flag
COPY --chown=1001:0 package.json package-lock.json ./

# Copy package.json and pnpm-lock.yaml before installing dependencies
COPY package.json pnpm-lock.yaml ./

# Install dependencies using pnpm
RUN pnpm install --frozen-lockfile
# Install dependencies as non-root user
USER 1001
RUN npm install --frozen-lockfile

# Copy the rest of the application files
COPY . .

# Build the application (if necessary)
RUN pnpm build || echo "No build step found, skipping"
COPY --chown=1001:0 . .

# Use a minimal base image for runtime
FROM --platform=$TARGETPLATFORM registry.access.redhat.com/ubi9/nodejs-20

ENV NODE_ENV=production
FROM registry.access.redhat.com/ubi9/nodejs-20

# Set working directory
WORKDIR /app

# Copy built files and dependencies
COPY --from=builder --chown=1001:0 /app /app

# Switch to non-root user
USER 1001

# Copy built files and dependencies
COPY --from=builder /app /app
ENV NODE_ENV=production

# Expose the application port
EXPOSE 8080
Expand Down
6 changes: 3 additions & 3 deletions transform-jsonata/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ broker <- trigger <- (response) <-
Assuming current working directory is `transform-jsonata`

```shell
pnpm dev
npm dev

# or pnpm dev-kubevirt to inject a different example transformation
# or npm dev-kubevirt to inject a different example transformation
```

### Tracing

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

pnpm dev-zipkin
npm dev-zipkin
```

## Building
Expand Down
Loading

0 comments on commit ce9a12e

Please sign in to comment.