Skip to content

Commit fed80a1

Browse files
committed
updates to do everything in the github actions
1 parent c06abfa commit fed80a1

File tree

4 files changed

+44
-2090
lines changed

4 files changed

+44
-2090
lines changed
Lines changed: 44 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,140 +1,69 @@
1-
name: Build Layer ZIP
1+
name: Build Sharp Lambda Layers
22

33
on:
44
push:
5-
branches:
6-
- main
7-
pull_request:
8-
branches:
9-
- main
10-
workflow_dispatch: # Allows manual triggering
5+
branches: [main]
6+
workflow_dispatch:
117

128
jobs:
13-
# Setup job to determine Sharp version and check release existence once
14-
setup:
15-
runs-on: ubuntu-latest
16-
outputs:
17-
sharp_version: ${{ steps.vars.outputs.sharp_version }}
18-
release_exists: ${{ steps.vars.outputs.release_exists }}
19-
steps:
20-
- name: Checkout
21-
uses: actions/checkout@v4
22-
with:
23-
fetch-depth: 0 # Needed for tag checking
24-
25-
- name: Install jq
26-
run: sudo apt-get update && sudo apt-get install -y jq
27-
28-
- name: Get Sharp Version and Check Release
29-
id: vars
30-
run: |
31-
content=$(cat ./package-lock.json)
32-
sharp_version=$(echo $content | jq -r '.packages."node_modules/sharp".version')
33-
if [ -z "$sharp_version" ] || [ "$sharp_version" == "null" ]; then
34-
echo "Error: Could not extract sharp version from package-lock.json"
35-
exit 1
36-
fi
37-
echo "Determined Sharp version: $sharp_version"
38-
echo "sharp_version=$sharp_version" >> $GITHUB_OUTPUT
39-
40-
release_exists="false"
41-
# Check if tag exists locally first (faster)
42-
if git rev-parse "v${sharp_version}" >/dev/null 2>&1; then
43-
release_exists="true"
44-
else
45-
# If not local, check remote tags
46-
git ls-remote --tags origin | grep -q "refs/tags/v${sharp_version}$" && release_exists="true" || release_exists="false"
47-
fi
48-
49-
echo "Release tag v${sharp_version} exists: $release_exists"
50-
echo "release_exists=$release_exists" >> $GITHUB_OUTPUT
51-
52-
53-
# Build job using matrix for architectures
54-
build:
55-
needs: setup
9+
build-layers:
5610
runs-on: ubuntu-latest
5711
strategy:
5812
matrix:
59-
# Define the platforms and corresponding simple architecture names
6013
include:
61-
- platform: linux/amd64
62-
arch: x64
63-
- platform: linux/arm64
64-
arch: arm64
14+
- arch: x64
15+
image: public.ecr.aws/lambda/nodejs:20
16+
- arch: arm64
17+
image: public.ecr.aws/lambda/nodejs:20-arm64
18+
6519
steps:
66-
- name: Checkout
20+
- name: Checkout repo
6721
uses: actions/checkout@v4
6822

69-
- name: Set up QEMU
70-
uses: docker/setup-qemu-action@v3
71-
72-
- name: Set up Docker Buildx
73-
uses: docker/setup-buildx-action@v3
74-
75-
- name: Build Docker image for ${{ matrix.arch }}
76-
uses: docker/build-push-action@v6
77-
with:
78-
context: .
79-
file: ./Dockerfile
80-
# Specify the platform for the build
81-
platforms: ${{ matrix.platform }}
82-
# Pass the architecture name as a build argument
83-
build-args: |
84-
TARGET_ARCH=${{ matrix.arch }}
85-
# Load the image into the local Docker daemon to extract files
86-
# Alternatively, use 'outputs: type=local,dest=output-docker'
87-
# then copy from 'output-docker/dist/...' in the next step.
88-
# Loading is simpler here if we just need the zip.
89-
load: true
90-
tags: sharp-aws-lambda-layer:${{ matrix.arch }}-dev # Tag with arch
91-
92-
- name: Create dist directory
93-
run: mkdir -p dist # Create directory if it doesn't exist
94-
95-
- name: Copy artifact (${{ matrix.arch }})
96-
# Run a temporary container from the built image to copy the specific zip file
23+
- name: Build & zip Sharp layer (${{ matrix.arch }})
9724
run: |
98-
docker run --rm -v "${{ github.workspace }}/dist":/output \
99-
sharp-aws-lambda-layer:${{ matrix.arch }}-dev \
100-
cp /build/dist/sharp-layer-${{ matrix.arch }}.zip /output/
101-
102-
- name: Upload artifact (${{ matrix.arch }})
25+
# mount workspace into the Lambda build image
26+
docker run --rm \
27+
-v "${{ github.workspace }}":/project \
28+
-w /project \
29+
${{ matrix.image }} \
30+
bash -exlc "
31+
# install only runtime deps for Sharp
32+
npm ci --no-optional --no-audit --production --arch=${{ matrix.arch }} --platform=linux
33+
34+
# stage into the Lambda layer layout
35+
mkdir -p layer/nodejs/node_modules
36+
cp -R node_modules/sharp layer/nodejs/node_modules/
37+
38+
# zip it
39+
(cd layer && zip -r ../sharp-layer-${{ matrix.arch }}.zip .)
40+
"
41+
42+
- name: Upload artifacts
10343
uses: actions/upload-artifact@v4
10444
with:
105-
name: sharp-layer-${{ matrix.arch }} # Artifact name includes arch
106-
path: dist/sharp-layer-${{ matrix.arch }}.zip # Path to the specific zip file
45+
name: sharp-layer-${{ matrix.arch }}
46+
path: sharp-layer-${{ matrix.arch }}.zip
10747

108-
# Release job runs after all builds complete
10948
release:
110-
needs: [setup, build] # Depends on setup for version and build for artifacts
49+
needs: build-layers
50+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
11151
runs-on: ubuntu-latest
112-
# Only run on push to main, and if the release doesn't exist yet
113-
# You might want to adjust this condition (e.g., always create/overwrite?)
114-
if: github.event_name == 'push' && github.ref == 'refs/heads/main' # && needs.setup.outputs.release_exists == 'false'
52+
11553
steps:
116-
- name: Download all artifacts
54+
- name: Download Sharp zips
11755
uses: actions/download-artifact@v4
11856
with:
119-
# Specify a pattern to download only the relevant ZIPs
120-
pattern: sharp-layer-*
121-
path: dist # Download to 'dist' directory
122-
# merge-multiple: true # Still not strictly needed as names are unique, but doesn't hurt
123-
124-
- name: List downloaded files
125-
run: ls -R dist
57+
path: dist
12658

127-
- name: Create or Update GitHub Release
59+
- name: Create or update GitHub Release
12860
uses: svenstaro/upload-release-action@v2
12961
with:
13062
repo_token: ${{ secrets.GITHUB_TOKEN }}
131-
# Use the sharp version determined in the setup job
132-
tag: v${{ needs.setup.outputs.sharp_version }}
133-
release_name: Sharp v${{ needs.setup.outputs.sharp_version }} Layer
134-
# Upload all zip files found in the 'dist' directory's subdirectories
135-
# Adjust the pattern if download-artifact structure is different
136-
file: dist/sharp-layer-*/*.zip
137-
file_glob: true # Enable globbing for the 'file' input
138-
overwrite: true # Overwrite existing assets in the release if tag exists
139-
body: "AWS Lambda Layer for Sharp v${{ needs.setup.outputs.sharp_version }}. Includes builds for x64 (amd64) and arm64."
140-
# make_latest: true # Optionally mark as latest release
63+
tag: v${{ github.sha }}
64+
release_name: Sharp Lambda Layer
65+
file: dist/*.zip
66+
file_glob: true
67+
overwrite: true
68+
body: |
69+
AWS Lambda layers for Sharp (x64 and arm64).

0 commit comments

Comments
 (0)