Skip to content

Commit

Permalink
refactor: update to @getcronit/pylon with bun and ZITADEL
Browse files Browse the repository at this point in the history
  • Loading branch information
schettn committed Jul 1, 2024
1 parent ac2b78f commit 374c5e7
Show file tree
Hide file tree
Showing 19 changed files with 526 additions and 1,573 deletions.
115 changes: 63 additions & 52 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,61 @@
# SPDX-License-Identifier: (EUPL-1.2)
# Copyright © 2022 snek.at
FROM --platform=linux/amd64 node:18-bookworm
# use the official Bun image
# see all versions at https://hub.docker.com/r/oven/bun/tags
FROM oven/bun:1 as base

LABEL description="This container serves as an entry point for our future Snek Function projects."
LABEL org.opencontainers.image.source="https://github.com/snek-functions/lens"
LABEL maintainer="opensource@snek.at"
LABEL description="This container serves as an entry point for our future Pylon projects."
LABEL org.opencontainers.image.source="https://github.com/cronitio/pylon-template"
LABEL maintainer="opensource@cronit.io"

ARG DEFAULT_PASSPHRASE="changeme"

ENV LAMBDA_TASK_ROOT=/var/task \
SNEK_FUNCTIONS_BUILD_DIR=/tmp/snek-functions \
HOME=/var/task \
PASSPHRASE=$DEFAULT_PASSPHRASE

WORKDIR ${LAMBDA_TASK_ROOT}

COPY --from=amazon/aws-lambda-nodejs:latest /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
COPY --from=amazon/aws-lambda-nodejs:latest /var/runtime /var/runtime
COPY --from=amazon/aws-lambda-nodejs:latest /var/lang /var/lang
COPY --from=amazon/aws-lambda-nodejs:latest lambda-entrypoint.sh .
COPY --from=amazon/aws-lambda-nodejs:latest /etc/pki/tls/certs/ca-bundle.crt /etc/pki/tls/certs/ca-bundle.crt
# Override /bin/sh because some scripts are only compatible with the amazon version
COPY --from=amazon/aws-lambda-nodejs:latest /bin/sh /bin/sh

# Add static files from . to task root
COPY package.json entrypoint.sh ${LAMBDA_TASK_ROOT}/
# Copy all files form the . to the build dir
COPY ./ ${SNEK_FUNCTIONS_BUILD_DIR}/

#RUN chmod +x entrypoint.sh

WORKDIR ${SNEK_FUNCTIONS_BUILD_DIR}
WORKDIR /usr/src/pylon

# install dependencies into temp directory
# this will cache them and speed up future builds
FROM base AS install
ARG NODE_VERSION=20
RUN apt update \
&& apt install -y curl
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

RUN mkdir -p /temp/dev
COPY package.json bun.lockb /temp/dev/

RUN cd /temp/dev && bun install --frozen-lockfile

# install with --production (exclude devDependencies)
RUN mkdir -p /temp/prod
COPY package.json bun.lockb /temp/prod/

RUN cd /temp/prod && bun install --frozen-lockfile --production

# copy node_modules from temp directory
# then copy all (non-ignored) project files into the image
FROM install AS prerelease
COPY --from=install /temp/dev/node_modules node_modules
COPY . .

# [optional] tests & build
ENV NODE_ENV=production
# RUN bun test
RUN bun run pylon build

# copy production dependencies and source code into final image
FROM base AS release
RUN apt-get update -y && apt-get install -y openssl
COPY --from=install /temp/prod/node_modules node_modules
COPY --from=prerelease /usr/src/pylon/.pylon .pylon
COPY --from=prerelease /usr/src/pylon/package.json .
COPY --from=prerelease /usr/src/pylon/entrypoint.sh .
COPY --from=prerelease /usr/src/pylon/requirements.txt .
COPY --from=prerelease /usr/src/pylon/src/internal src/internal

# Grant bun user permission to write /usr/src/pylon/data
RUN mkdir -p /usr/src/pylon/data
RUN chown -R bun:bun /usr/src/pylon/data

# Update, install and cleaning:
RUN set -ex \
Expand All @@ -42,21 +67,13 @@ RUN set -ex \
" \
&& apt-get update && apt-get install -y --no-install-recommends $BUILD_DEPS \
#&& ln -s /usr/local/bin/node /var/lang/bin/node \
&& yarn install --production \
&& yarn sf build \
# Copy the built functions to the lambda function
&& rm -rf venv \
&& mkdir -p venv/bin \
&& ln -s $(which python3) venv/bin/python \
&& venv/bin/python -m pip install -U pip --break-system-packages \
&& venv/bin/python -m pip install -r requirements.txt --break-system-packages \
&& pip3 install --no-cache-dir -r requirements.txt \
&& find src -mindepth 1 -maxdepth 1 -not -name internal -exec rm -rf {} + \
&& mv .sf src node_modules venv ${LAMBDA_TASK_ROOT} \
&& rm -r ${SNEK_FUNCTIONS_BUILD_DIR}/* \
&& mkdir -p ${LAMBDA_TASK_ROOT}/.ssh \
&& mkdir -p ${LAMBDA_TASK_ROOT}/ansible \
&& touch ${LAMBDA_TASK_ROOT}/ansible/.ansible.cfg \
&& ln -s ${LAMBDA_TASK_ROOT}/ansible/.ansible.cfg ${LAMBDA_TASK_ROOT}/.ansible.cfg \
&& mkdir -p .ssh \
&& mkdir -p ansible \
&& touch ansible/.ansible.cfg \
&& ln -s ansible/.ansible.cfg .ansible.cfg \
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false $BUILD_DEPS \
&& rm -rf /var/lib/apt/lists

Expand All @@ -72,16 +89,10 @@ RUN set -ex \
&& apt-get update && apt-get install -y --no-install-recommends $RUN_DEPS \
&& rm -rf /var/lib/apt/lists/*

WORKDIR ${LAMBDA_TASK_ROOT}

EXPOSE 3000

VOLUME [ "/var/task/data" ]

# run the app
USER bun
EXPOSE 3000/tcp
ENTRYPOINT [ "./entrypoint.sh" ]

# Start in serverless mode
#CMD [ "app.handler" ]

# SPDX-License-Identifier: (EUPL-1.2)
# Copyright © 2022 snek.at
VOLUME [ "/usr/src/pylon" ]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ This repository serves as an entry point for all future projects.

SPDX-License-Identifier: (EUPL-1.2)
Copyright © 2019-2022 snek.at
docker pull ghcr.io/snek-functions/lens@sha256:8204bb6ab97e8d4ed0930c8dbb79fa4f5b2cbcbe0e3dd960630d8d3a950c4478
Binary file added bun.lockb
Binary file not shown.
16 changes: 1 addition & 15 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,4 @@
cp -f /.ssh/..data/* ${LAMBDA_TASK_ROOT}/.ssh/
chmod 600 -Rv ${LAMBDA_TASK_ROOT}/.ssh/

if [ $# -ne 1 ]; then
echo "Start in continuous mode" 1>&2
exec yarn sf-server --https --key /private/tls.key --cert /private/tls.crt --passphrase $PASSPHRASE
fi
export _HANDLER="$1"

RUNTIME_ENTRYPOINT=/var/runtime/bootstrap
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
exec /usr/local/bin/aws-lambda-rie $RUNTIME_ENTRYPOINT
else
exec $RUNTIME_ENTRYPOINT
fi

# SPDX-License-Identifier: (EUPL-1.2)
# Copyright © 2019-2022 snek.at
bun pylon-server --https --key /private/tls.key --cert /private/tls.crt --passphrase $PASSPHRASE
34 changes: 21 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"./client": "./src/client/index.ts",
"./package.json": "./package.json"
},
"pylon": {
"external": [
"bun",
"ws"
]
},
"typesVersions": {
"*": {
"./client": [
Expand All @@ -25,25 +31,27 @@
}
},
"dependencies": {
"@snek-at/function": "*",
"@snek-at/function-cli": "*",
"@snek-at/function-server": "*",
"@snek-functions/jwt": "^0.0.38",
"@types/http-proxy": "^1.17.11",
"dotenv": "^16.3.1",
"http-proxy": "^1.18.1",
"ip": "^1.1.8",
"@getcronit/pylon": "^1.0.0",
"@getcronit/pylon-cli": "^1.0.0",
"@getcronit/pylon-server": "^1.0.0",
"@squarecloud/http-proxy": "^1.0.0",
"@types/http-proxy": "^1.17.14",
"axios": "^1.7.2",
"dotenv": "^16.4.5",
"ip": "^1.1.9",
"net": "^1.0.2",
"snek-query": "^0.0.83"
"node-fetch": "^3.3.2",
"undici": "^6.19.2"
},
"devDependencies": {
"@types/dotenv": "^8.2.0",
"@types/ip": "^1.1.0",
"commitizen": "^4.2.5",
"@types/ip": "^1.1.3",
"bun-types": "^1.1.16",
"commitizen": "^4.3.0",
"git-cz": "^4.9.0"
},
"scripts": {
"develop": "yarn sf develop",
"build": "yarn sf build"
"develop": "yarn pylon develop",
"build": "yarn pylon build"
}
}
1 change: 0 additions & 1 deletion services.json

This file was deleted.

2 changes: 0 additions & 2 deletions src/clients/origin/.gitignore

This file was deleted.

16 changes: 0 additions & 16 deletions src/clients/origin/src/index.ts

This file was deleted.

Loading

0 comments on commit 374c5e7

Please sign in to comment.