Skip to content

Commit 970e5a4

Browse files
authored
Merge pull request #8 from bubblydoo/setup-github-actions
Setup Github actions
2 parents 209f189 + 60244e5 commit 970e5a4

File tree

9 files changed

+150
-54
lines changed

9 files changed

+150
-54
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
**
2+
!package-lock.json
3+
!package.json
4+
!webpack.config.js

.github/workflows/docker-workflow.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: Build Layer ZIP
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 0
19+
- name: Read version
20+
id: package_lock_json
21+
run: |
22+
content=$(cat ./package-lock.json)
23+
content="${content//'%'/'%25'}"
24+
content="${content//$'\n'/'%0A'}"
25+
content="${content//$'\r'/'%0D'}"
26+
echo "::set-output name=packageLockJson::$content"
27+
- name: Variables
28+
id: vars
29+
run: |
30+
sharp_version="${{ fromJSON(steps.package_lock_json.outputs.packageLockJson).dependencies.sharp.version }}"
31+
echo "::set-output name=sharp_version::$sharp_version"
32+
33+
release_exists="true"
34+
git show-ref --tags --quiet --verify -- "refs/tags/$sharp_version" || release_exists="false"
35+
echo "::set-output name=release_exists::$release_exists"
36+
- name: Build
37+
id: docker_build
38+
uses: docker/build-push-action@v2
39+
with:
40+
context: .
41+
file: ./Dockerfile
42+
tags: amazon-linux-sharp-layer:dev
43+
- name: Copy artifacts
44+
run: docker run -v "${{ github.workspace }}/dist":/dist amazon-linux-sharp-layer:dev
45+
- name: Upload artifacts
46+
uses: actions/upload-artifact@v2
47+
with:
48+
name: sharp-lambda-layer.zip
49+
path: dist/sharp-layer.zip
50+
if-no-files-found: error
51+
- name: Create release
52+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.vars.outputs.release_exists == 'false' }}
53+
id: create_release
54+
uses: actions/create-release@v1
55+
env:
56+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
with:
58+
tag_name: ${{ steps.vars.outputs.sharp_version }}
59+
release_name: Version ${{ steps.vars.outputs.sharp_version }}
60+
prerelease: ${{ contains(steps.vars.outputs.sharp_version, '-') }}
61+
- name: Upload release asset
62+
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' && steps.vars.outputs.release_exists == 'false' }}
63+
id: upload_release_asset
64+
uses: actions/upload-release-asset@v1
65+
env:
66+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
67+
with:
68+
upload_url: ${{ steps.create_release.outputs.upload_url }}
69+
asset_path: dist/sharp-layer.zip
70+
asset_name: sharp-lambda-layer.zip
71+
asset_content_type: application/zip

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.idea/
22
coverage
33
node_modules/
4-
dist/*
5-
!dist/sharp-layer.zip
4+
dist/
65
*.iml
76
.DS_Store

Dockerfile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM lambci/lambda:build-nodejs12.x
2+
3+
WORKDIR /build
4+
5+
COPY * ./
6+
7+
RUN npm --no-optional --no-audit --progress=false install
8+
9+
RUN node ./node_modules/webpack/bin/webpack.js
10+
11+
RUN node -e "console.log(require('sharp'))"
12+
13+
RUN mkdir /dist && \
14+
echo "cp /build/dist/sharp-layer.zip /dist/sharp-layer.zip" > /entrypoint.sh && \
15+
chmod +x /entrypoint.sh
16+
17+
ENTRYPOINT "/entrypoint.sh"

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
This AWS lambda layer contains a pre-built [sharp](https://www.npmjs.com/package/sharp) npm library.
33
It is optimized for the most frugal space usage possible.
44

5-
|Sharp version| Layer size|
6-
|---|---|
7-
|[0.26.0](https://github.com/lovell/sharp/releases/tag/v0.26.0)|9.68MB|
8-
95
# Getting
10-
A pre-built layer zip file is available at [`dist/sharp-layer.zip`](./dist/sharp-layer.zip).
6+
A pre-built layer zip file is available on the [Releases page](../../releases), alongside the size of the layer.
117

128
# Building
139

dist/sharp-layer.zip

-9.69 MB
Binary file not shown.

package-lock.json

Lines changed: 53 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"copy-webpack-plugin": "^6.1.0"
1212
},
1313
"dependencies": {
14-
"sharp": "^0.26.0"
14+
"sharp": "^0.27.0"
1515
},
1616
"engines": {
1717
"node": ">=12.14.0"

webpack.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ module.exports = {
3535
})
3636
],
3737
optimization: {
38-
minimize: true,
38+
// minimize will be enabled in Github Actions
39+
minimize: process.env.NODE_ENV === 'production',
3940
},
4041
output: {
4142
filename: '[name].js',

0 commit comments

Comments
 (0)