forked from bubblydoo/lambda-layer-sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (99 loc) · 4.02 KB
/
docker-workflow.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Build Layer ZIP
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Read version
id: package_lock_json
run: |
content=$(cat ./package-lock.json)
content="${content//'%'/'%25'}"
content="${content//$'\n'/'%0A'}"
content="${content//$'\r'/'%0D'}"
echo "::set-output name=packageLockJson::$content"
- name: Variables
id: vars
run: |
sharp_version="${{ fromJSON(steps.package_lock_json.outputs.packageLockJson).dependencies.sharp.version }}"
echo "::set-output name=sharp_version::$sharp_version"
release_exists="true"
git show-ref --tags --quiet --verify -- "refs/tags/$sharp_version" || release_exists="false"
echo "::set-output name=release_exists::$release_exists"
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build
id: docker_build
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
# platforms: linux/amd64,linux/arm64
tags: amazon-linux-sharp-layer:dev
# this action should be replaced with load: true in the docker_build action, see https://github.com/docker/buildx/issues/59
- name: Load Docker images
run: |
docker buildx build --load --platform linux/amd64 -t amazon-linux-sharp-layer:dev-x86_64 . &&
# docker buildx build --load --platform linux/arm64 -t amazon-linux-sharp-layer:dev-aarch64 . &&
echo 'done'
- name: Copy artifacts x86_64
run: docker run --platform linux/amd64 -v "${{ github.workspace }}/dist-x86_64":/dist amazon-linux-sharp-layer:dev-x86_64
# - name: Copy artifacts aarch64
# run: docker run --platform linux/arm64 -v "${{ github.workspace }}/dist-aarch64":/dist amazon-linux-sharp-layer:dev-aarch64
- name: Upload artifacts x86_64
uses: actions/upload-artifact@v2
with:
name: sharp-lambda-layer.x86_64.zip
path: dist-x86_64/sharp-lambda-layer.zip
if-no-files-found: error
# - name: Upload artifacts aarch64
# uses: actions/upload-artifact@v2
# with:
# name: sharp-lambda-layer.aarch64.zip
# path: dist-aarch64/sharp-lambda-layer.zip
# if-no-files-found: error
- name: Create release
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.vars.outputs.release_exists == 'false' }}
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.vars.outputs.sharp_version }}
release_name: Version ${{ steps.vars.outputs.sharp_version }}
prerelease: ${{ contains(steps.vars.outputs.sharp_version, '-') }}
- name: Upload release asset x86_64
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.vars.outputs.release_exists == 'false' }}
id: upload_release_asset_x86_64
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: dist-x86_64/sharp-lambda-layer.zip
asset_name: sharp-lambda-layer.x86_64.zip
asset_content_type: application/zip
# - name: Upload release asset aarch64
# if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.vars.outputs.release_exists == 'false' }}
# id: upload_release_asset_aarch64
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: dist/sharp-layer.aarch64.zip
# asset_name: sharp-lambda-layer.aarch64.zip
# asset_content_type: application/zip