Skip to content

Commit 3c66125

Browse files
committed
fix: make avif files work
there seems to be an issue with the precompiled arm binaries for sharp's `libvips` that do not work properly on Amazon's Graviton CPUs. This PR mainly changes the CPU architecture back to `x86_64`, but also bumps the runtime to the latest `node24.x`
1 parent c9d2af6 commit 3c66125

File tree

8 files changed

+229
-215
lines changed

8 files changed

+229
-215
lines changed

.github/workflows/deploy.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ jobs:
2525
image-handler:
2626
env:
2727
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28-
runs-on: ubuntu-latest-arm64
28+
runs-on: ubuntu-latest
2929

3030
steps:
31-
- uses: actions/checkout@v5
31+
- uses: actions/checkout@v6
3232
- uses: actions/setup-node@v6
3333
with:
34-
node-version: '20'
34+
node-version: '24'
3535
cache: 'npm'
3636
cache-dependency-path: 'source/image-handler/package-lock.json'
3737

38-
- name: install
39-
run: make npm/install
40-
- name: test
41-
run: make npm/test
4238
- name: build
4339
run: make build
4440

Makefile

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,31 @@ clean:
2222
@echo "+ $@"
2323
@cd $(WORK_DIR) && rm -rf ./dist/ ./node_modules/
2424

25-
.PHONY: npm/install
26-
npm/install:
27-
@echo "+ $@"
28-
cd $(WORK_DIR) && npm install --cpu=arm64 --os=linux --libc=musl
29-
3025
.PHONY: npm/test
3126
npm/test:
3227
@echo "+ $@"
3328
cd $(WORK_DIR) && npm run test
3429

30+
uname_platform := $(shell uname -m)
31+
uname_os := $(shell uname -s)
32+
3533
.PHONY: build
36-
build: ## Builds the function
34+
build: clean ## Builds the function
3735
@echo "+ $@"
38-
cd $(WORK_DIR) && npm run test && npm run build
36+
if [ "$(uname_platform)" != "x86_64" ] || [ "$(uname_os)" != "Linux" ]; then \
37+
docker run \
38+
--platform linux/amd64 \
39+
--rm --workdir /app \
40+
--volume ./$(WORK_DIR):/app \
41+
--entrypoint sh amazon/aws-lambda-nodejs:24.2025.11.23.13-x86_64 \
42+
-c 'npm run test && npm run build && npm install --include=optional --cpu=x64 --os=linux --libc=glibc --prefix ./dist [email protected]' ; \
43+
else \
44+
cd $(WORK_DIR) && \
45+
npm run test && \
46+
npm run build && \
47+
npm install --include=optional --cpu=x64 --os=linux --libc=glibc --prefix ./dist [email protected] ; \
48+
fi
49+
cd $(WORK_DIR) && npm run zip
3950

4051
tf: ## Runs `terraform`
4152
rm -f $(WORK_DIR)/terraform/.terraform/terraform.tfstate || true
@@ -56,7 +67,7 @@ help: ## Display this help screen
5667
providers: update ## Upgrades all providers and platform independent dependency locks (slow)
5768
@echo "+ $@"
5869
@for f in $(TF_FOLDERS) ; do \
59-
echo upgrading: $$f ;\
70+
echo upgrading: $$f ;\
6071
terraform -chdir=$$f init -upgrade=true -backend=false;\
6172
terraform -chdir=$$f providers lock -platform=darwin_amd64 -platform=darwin_arm64 -platform=linux_amd64 ;\
6273
done
@@ -66,8 +77,8 @@ update: ## Upgrades Terraform core, providers and modules constraints recursivel
6677
@echo "+ $@"
6778
@command -v tfupdate >/dev/null 2>&1 || { echo >&2 "Please install tfupdate: 'brew install minamijoyo/tfupdate/tfupdate'"; exit 1; }
6879
@tfupdate terraform -v "~> 1" -r .
69-
@tfupdate module -v "7.5.0" registry.terraform.io/moritzzimmer/lambda/aws -r .
70-
@tfupdate module -v "7.5.0" registry.terraform.io/moritzzimmer/lambda/aws//modules/deployment -r .
71-
@tfupdate provider aws -v "~> 5" -r .
80+
@tfupdate module -v "8.4.0" registry.terraform.io/moritzzimmer/lambda/aws -r .
81+
@tfupdate module -v "8.4.0" registry.terraform.io/moritzzimmer/lambda/aws//modules/deployment -r .
82+
@tfupdate provider aws -v "~> 6" -r .
7283
@tfupdate provider opensearch -v "~> 2" -r .
7384

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,27 @@ The following environment variables are used by the image-handler:
6767

6868
To build the package run:
6969

70-
```make FUNC=image-handler build```
70+
```shell
71+
make build
72+
```
73+
74+
The final package will be located in `source/image-handler/dist/image-handler.zip`.
7175

7276
### Testing
7377

74-
Run tests using the following Make command:
78+
Run tests (also installs packages defined in package.json) using the following Make command:
7579

76-
```make npm/test```
80+
```shell
81+
make npm/test
82+
```
7783

7884
### Infrastructure deployment
7985

8086
Deploy the infrastructure using Terraform with the following Make command:
8187

82-
```make FUNC=image-handler tf```
88+
```shell
89+
make tf
90+
```
8391

8492
## Special interest section
8593

@@ -144,14 +152,7 @@ If required once more, they need to be pulled from the original repository:
144152

145153
### Updating Sharp version
146154

147-
You need to keep the sharp version in `package.json` and the lambda layer in sync.
148-
149-
First, create a new lambda layer version with the updated sharp version.
150-
151-
```terraform
152-
locals {
153-
sharp_version = "0.34.4"
154-
}
155-
```
155+
You need to keep the sharp version in both:
156156

157-
Then update the function code and create a new lambda version.
157+
* `package.json`
158+
* within the `Makefile` (search for `sharp@`)

0 commit comments

Comments
 (0)