-
Notifications
You must be signed in to change notification settings - Fork 104
160 lines (136 loc) · 6.55 KB
/
ci.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
name: ci
on:
# Run on any push to main or any tag
push:
branches:
- main
tags:
- '*'
# Run on any pull request
pull_request:
branches:
- main
jobs:
build-bin:
name: bin
runs-on: ubuntu-latest
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Cache docker registry
uses: actions/cache@v3
with:
key: registry-${{ github.sha }}
path: ${{ runner.temp }}/registry
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
# Key is named differently to avoid collision
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Start local Docker registry
run: |
# Docker save / load does not support multi-arch images.
# This sets up a local registry that I can push the images to.
docker run -d -p 5000:5000 -e 'REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry' -v '${{ runner.temp }}/registry:/var/lib/registry' registry:2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Build image
run: |
docker buildx build -f bin.dockerfile --provenance=false --platform=linux/amd64,linux/arm64 -t localhost:5000/bin --push .
build:
needs: build-bin
name: ${{ matrix.kind }}
runs-on: ubuntu-latest
strategy:
matrix:
kind: ["alpine", "debian", "distroless", "ubuntu"]
steps:
- name: Clone repository
uses: actions/checkout@v4
- name: Cache docker registry
uses: actions/cache@v3
with:
key: registry-${{ github.sha }}
fail-on-cache-miss: true
path: ${{ runner.temp }}/registry
- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
# Key is named differently to avoid collision
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-multi-buildx
- name: Start local Docker registry
run: |
# Docker save / load does not support multi-arch images.
# This sets up a local registry that I can push the images to.
docker run -d -p 5000:5000 -e 'REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY=/var/lib/registry' -v '${{ runner.temp }}/registry:/var/lib/registry' registry:2
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: network=host
- name: Build image
run: |
docker buildx build -f ${{ matrix.kind }}.dockerfile --provenance=false --platform=linux/amd64,linux/arm64 --build-arg BIN_IMAGE=localhost:5000/bin -t localhost:5000/${{ matrix.kind }} --push .
- name: Test default CMD
run: |
docker run -t localhost:5000/${{ matrix.kind }}
- name: Test if entry script forwards to deno binary
run: |
docker run -t --platform linux/arm64 localhost:5000/${{ matrix.kind }} eval 'console.log(`Welcome to Deno ${Deno.build.arch}!`)'
docker run -t --platform linux/amd64 localhost:5000/${{ matrix.kind }} eval 'console.log(`Welcome to Deno ${Deno.build.arch}!`)'
# if typescript is present in the output, then probably deno --version worked
docker run -t localhost:5000/${{ matrix.kind }} --version | grep typescript
- name: Test if entry script forwards to other binaries
if: ${{ matrix.kind != 'distroless' }}
run: |
docker run -t localhost:5000/${{ matrix.kind }} deno eval 'console.log(`Welcome to Deno ${Deno.build.arch}!`)'
docker run -t localhost:5000/${{ matrix.kind }} echo 'test entry script'
- name: Login to Docker Hub
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Push named images
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag'
run: |
docker buildx imagetools create localhost:5000/${{ matrix.kind }} -t denoland/deno:${{ matrix.kind }}-${{ github.ref_name }} -t denoland/deno:${{ matrix.kind }}
docker pull --platform linux/amd64 denoland/deno:${{ matrix.kind }}-${{ github.ref_name }}
docker pull --platform linux/amd64 denoland/deno:${{ matrix.kind }}
docker pull --platform linux/arm64 denoland/deno:${{ matrix.kind }}-${{ github.ref_name }}
docker pull --platform linux/arm64 denoland/deno:${{ matrix.kind }}
- name: Push bin image
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
run: |
docker buildx imagetools create localhost:5000/bin -t denoland/deno:bin-${{ github.ref_name }} -t denoland/deno:bin
docker pull --platform linux/amd64 denoland/deno:bin-${{ github.ref_name }}
docker pull --platform linux/amd64 denoland/deno:bin
docker pull --platform linux/arm64 denoland/deno:bin-${{ github.ref_name }}
docker pull --platform linux/arm64 denoland/deno:bin
- name: Push default images
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian'
run: |
docker buildx imagetools create localhost:5000/${{ matrix.kind }} -t denoland/deno:${{ github.ref_name }} -t denoland/deno:latest
docker pull --platform linux/amd64 denoland/deno:${{ github.ref_name }}
docker pull --platform linux/amd64 denoland/deno:latest
docker pull --platform linux/arm64 denoland/deno:${{ github.ref_name }}
docker pull --platform linux/arm64 denoland/deno:latest
- name: Update Docker Hub Description
if: github.repository == 'denoland/deno_docker' && github.ref_type == 'tag' && matrix.kind == 'debian' # Only on a tag and once per run (on debian run)
uses: peter-evans/dockerhub-description@e98e4d1628a5f3be2be7c231e50981aee98723ae # v4.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: denoland/deno
short-description: ${{ github.event.repository.description }}