Skip to content

Commit dc4e633

Browse files
authored
feat: initial version (#8)
1 parent cfc5e81 commit dc4e633

File tree

14 files changed

+7937
-0
lines changed

14 files changed

+7937
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
branches:
6+
- develop
7+
- main
8+
pull_request:
9+
branches:
10+
- main
11+
12+
permissions:
13+
contents: write
14+
issues: write
15+
pull-requests: write
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build-base:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- name: Set up Docker Buildx
27+
uses: docker/setup-buildx-action@v3
28+
- name: Login to GitHub Container Registry
29+
uses: docker/login-action@v3
30+
with:
31+
registry: ghcr.io
32+
username: ${{ github.actor }}
33+
password: ${{ secrets.GHCR_PAT }}
34+
- name: Build and push base
35+
run: |
36+
echo "${{ secrets.GHCR_PAT }}" > github_token
37+
docker buildx build \
38+
--platform linux/arm64 \
39+
--provenance=false \
40+
--secret id=github_token,src=github_token \
41+
--target base \
42+
--tag ghcr.io/${{ github.repository_owner }}/lambda-shell-runtime:base \
43+
--push \
44+
.
45+
env:
46+
GITHUB_TOKEN: ${{ secrets.GHCR_PAT }}
47+
48+
build:
49+
needs: build-base
50+
runs-on: ubuntu-latest
51+
env:
52+
HTTP_CLI_VERSION: v1.0.1
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: actions/setup-node@v3
56+
with:
57+
node-version: 20
58+
- uses: actions/cache@v3
59+
with:
60+
path: ~/.npm
61+
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
62+
restore-keys: |
63+
${{ runner.os }}-node-
64+
- run: npm ci
65+
- name: Set up QEMU
66+
uses: docker/setup-qemu-action@v3
67+
- name: Set up Docker Buildx
68+
uses: docker/setup-buildx-action@v3
69+
- name: Create and use buildx builder
70+
run: |
71+
docker buildx create --name shell-runtime-builder --driver docker-container --use
72+
docker buildx inspect shell-runtime-builder --bootstrap
73+
- name: Cache Docker layers
74+
uses: actions/cache@v3
75+
with:
76+
path: /tmp/.buildx-cache
77+
key: ${{ runner.os }}-buildx-${{ github.sha }}
78+
restore-keys: |
79+
${{ runner.os }}-buildx-
80+
- name: Set version
81+
id: version
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
run: |
85+
if [ "${{ github.ref_name }}" = "main" ]; then
86+
# Get semantic version for main branch
87+
VERSION=$(npx semantic-release --no-ci --dry-run --branch main 2>&1 | grep -oP 'The next release version is \K[0-9]+\.[0-9]+\.[0-9]+' || echo "")
88+
if [ -z "$VERSION" ]; then
89+
echo "No release needed"
90+
echo "VERSION=develop" >> $GITHUB_ENV
91+
echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
92+
else
93+
echo "VERSION=$VERSION" >> $GITHUB_ENV
94+
echo "SHOULD_RELEASE=true" >> $GITHUB_ENV
95+
fi
96+
else
97+
# Use branch name for develop
98+
echo "VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
99+
echo "SHOULD_RELEASE=false" >> $GITHUB_ENV
100+
fi
101+
echo "Detected VERSION: $VERSION"
102+
- name: Log in to GHCR
103+
run: echo "${{ secrets.GHCR_PAT }}" | docker login ghcr.io -u skunxicat --password-stdin
104+
- name: Build and push images
105+
run: |
106+
echo "${{ secrets.GHCR_PAT }}" > github_token
107+
export GITHUB_TOKEN="${{ secrets.GHCR_PAT }}"
108+
109+
# Build and push all variants
110+
make push VERSION="$VERSION" REGISTRY="ghcr.io/${{ github.repository_owner }}"
111+
shell: bash
112+
- name: Create release
113+
if: env.SHOULD_RELEASE == 'true'
114+
run: npx semantic-release
115+
env:
116+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
117+
GHCR_PAT: ${{ secrets.GHCR_PAT }}

.github/workflows/build-base.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: Build Base Image
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
paths:
7+
- 'Dockerfile'
8+
- 'runtime/**'
9+
- 'task/handler.sh'
10+
- '.github/workflows/build-base.yml'
11+
pull_request:
12+
branches: [ main ]
13+
paths:
14+
- 'Dockerfile'
15+
- 'runtime/**'
16+
- 'task/handler.sh'
17+
18+
permissions:
19+
contents: write
20+
issues: write
21+
pull-requests: write
22+
packages: write
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
jobs:
29+
build-base:
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v4
33+
34+
- name: Set up Docker Buildx
35+
uses: docker/setup-buildx-action@v3
36+
37+
- name: Login to GitHub Container Registry
38+
uses: docker/login-action@v3
39+
with:
40+
registry: ghcr.io
41+
username: ${{ github.actor }}
42+
password: ${{ secrets.GHCR_PAT }}
43+
44+
- name: Build and push base
45+
run: |
46+
echo "${{ secrets.GHCR_PAT }}" > github_token
47+
docker buildx build \
48+
--platform linux/arm64 \
49+
--provenance=false \
50+
--secret id=github_token,src=github_token \
51+
--target base \
52+
--tag ghcr.io/${{ github.repository_owner }}/lambda-shell-runtime:base \
53+
--push \
54+
.
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GHCR_PAT }}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build Installers
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
paths:
7+
- 'Dockerfile'
8+
- '.github/workflows/build-installers.yml'
9+
pull_request:
10+
branches: [ main ]
11+
paths:
12+
- 'Dockerfile'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
build-installers:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- uses: actions/checkout@v4
23+
24+
- name: Set up Docker Buildx
25+
uses: docker/setup-buildx-action@v3
26+
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GHCR_PAT }}
33+
34+
- name: Build and push installers
35+
run: |
36+
# Build awscurl-installer
37+
docker buildx build \
38+
--platform linux/arm64 \
39+
--provenance=false \
40+
--target awscurl-installer \
41+
--tag ghcr.io/${{ github.repository_owner }}/lambda-shell-runtime:awscurl-installer \
42+
--push \
43+
-f - . << 'EOF'
44+
FROM public.ecr.aws/lambda/provided:al2023 AS awscurl-installer
45+
RUN dnf install -y unzip python3-pip findutils && dnf clean all
46+
RUN pip3 install --no-cache-dir --target /tmp/awscurl awscurl && \
47+
find /tmp/awscurl -type d -name '__pycache__' -exec rm -rf {} + && \
48+
find /tmp/awscurl -type f -name '*.pyc' -delete && \
49+
find /tmp/awscurl -type d -name '*.dist-info' -exec rm -rf {} +
50+
EOF
51+
52+
# Build awscli-installer
53+
docker buildx build \
54+
--platform linux/arm64 \
55+
--provenance=false \
56+
--target awscli-installer \
57+
--tag ghcr.io/${{ github.repository_owner }}/lambda-shell-runtime:awscli-installer \
58+
--push \
59+
-f - . << 'EOF'
60+
FROM public.ecr.aws/lambda/provided:al2023 AS awscli-installer
61+
RUN dnf install -y aws-cli && dnf clean all
62+
EOF

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Docker artifacts
2+
*.tar
3+
*.tar.gz
4+
*.tar.xz
5+
*.tgz
6+
*.img
7+
8+
# Build output
9+
.DS_Store
10+
build/
11+
dist/
12+
*.log
13+
node_modules/
14+
15+
# VSCode settings
16+
.vscode/
17+
#examples/

Dockerfile

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
FROM public.ecr.aws/lambda/provided:al2023 AS builder
2+
3+
ARG HTTP_CLI_VERSION=v1.0.1
4+
5+
RUN dnf install -y unzip && \
6+
dnf clean all
7+
8+
# Download http-cli
9+
RUN curl \
10+
-L "https://github.com/ql4b/http-cli/archive/refs/tags/${HTTP_CLI_VERSION}.zip" \
11+
-o http-cli.zip && \
12+
unzip http-cli.zip && \
13+
mkdir -p /http-cli-bin && \
14+
mv http-cli-${HTTP_CLI_VERSION#v}/http-cli /http-cli-bin/ && \
15+
chmod +x /http-cli-bin/http-cli && \
16+
rm -rf http-cli.zip http-cli-${HTTP_CLI_VERSION#v}
17+
18+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
19+
20+
# base: minimal runtime setup with jq
21+
FROM public.ecr.aws/lambda/provided:al2023 AS base
22+
23+
ARG VERSION=develop
24+
ARG HTTP_CLI_VERSION
25+
26+
# Install only runtime dependencies
27+
RUN dnf install -y jq && \
28+
dnf clean all && \
29+
rm -rf /var/cache/dnf
30+
31+
# Copy http-cli
32+
COPY --from=builder /http-cli-bin/http-cli /var/task/bin/http-cli
33+
ENV PATH="/var/task/bin:${PATH}"
34+
35+
COPY runtime/bootstrap /var/runtime/bootstrap
36+
RUN chmod +x /var/runtime/bootstrap
37+
38+
WORKDIR /var/task
39+
40+
COPY task/handler.sh handler.sh
41+
42+
LABEL org.opencontainers.image.source="https://github.com/ql4b/lambda-shell-runtime"
43+
LABEL org.opencontainers.image.version="${VERSION}"
44+
45+
# tiny: add lambda helper functions
46+
FROM ghcr.io/ql4b/lambda-shell-runtime:base AS tiny
47+
48+
ARG VERSION
49+
ARG HTTP_CLI_VERSION
50+
51+
COPY task/helpers.sh helpers.sh
52+
53+
LABEL org.opencontainers.image.title="lambda-shell-runtime:tiny"
54+
LABEL org.opencontainers.image.version="${VERSION}"
55+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
56+
57+
# micro: includes awscurl
58+
FROM tiny AS micro
59+
60+
ARG VERSION
61+
ARG HTTP_CLI_VERSION
62+
63+
RUN dnf install -y python3 && \
64+
dnf clean all && \
65+
rm -rf /var/cache/dnf
66+
67+
COPY --from=ghcr.io/ql4b/lambda-shell-runtime:awscurl-installer /tmp/awscurl /var/task/aws
68+
RUN rm -rf \
69+
/var/task/aws/__pycache__ \
70+
/var/task/aws/*.dist-info \
71+
/var/task/aws/**/__pycache__
72+
73+
ENV PYTHONPATH="/var/task/aws"
74+
75+
RUN mkdir -p /var/task/bin && \
76+
printf '#!/bin/sh\nexport PYTHONPATH=/var/task/aws\nexec python3 -m awscurl.awscurl "$@"\n' > /var/task/bin/awscurl && \
77+
chmod +x /var/task/bin/awscurl
78+
79+
LABEL org.opencontainers.image.title="lambda-shell-runtime:micro"
80+
LABEL org.opencontainers.image.version="${VERSION}"
81+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"
82+
83+
# full: includes aws-cli for complete AWS functionality
84+
FROM tiny AS full
85+
86+
ARG VERSION
87+
ARG HTTP_CLI_VERSION
88+
89+
RUN dnf install -y awscli-2 && \
90+
dnf clean all && \
91+
rm -rf /var/cache/dnf
92+
93+
LABEL org.opencontainers.image.title="lambda-shell-runtime:full"
94+
LABEL org.opencontainers.image.version="${VERSION}"
95+
LABEL org.opencontainers.image.http_cli_version="${HTTP_CLI_VERSION}"

Makefile

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
.PHONY: help build push clean base tiny micro full
2+
3+
PLATFORM ?= linux/arm64
4+
TAG ?= lambda-shell-runtime
5+
VERSION ?= develop
6+
REGISTRY ?= ghcr.io/ql4b
7+
8+
help: ## Show this help
9+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}'
10+
11+
build: tiny micro full ## Build all variants locally
12+
13+
base: ## Build base image
14+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(TAG) --load base
15+
16+
tiny: base ## Build tiny variant
17+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(TAG) --load tiny
18+
19+
micro: base ## Build micro variant
20+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(TAG) --load micro
21+
22+
full: base ## Build full variant
23+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(TAG) --load full
24+
25+
push-base: ## Push base to registry
26+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(REGISTRY)/$(TAG) --push base
27+
28+
push: ## Push all variants to registry
29+
VERSION=$(VERSION) ./build --platform $(PLATFORM) --tag $(REGISTRY)/$(TAG) --push tiny micro full
30+
31+
clean: ## Remove local images
32+
docker rmi -f $(TAG):base $(TAG):tiny $(TAG):micro $(TAG):full 2>/dev/null || true

0 commit comments

Comments
 (0)