@@ -7,142 +7,146 @@ jobs:
7
7
supported-arch-matrix :
8
8
name : Supported processor architectures
9
9
runs-on : ubuntu-latest
10
- needs :
11
- - lint-dockerfile
10
+ # needs:
11
+ # - lint-dockerfile
12
12
outputs :
13
- arch : ${{ steps.supported-arch-matrix.outputs.arch }}
13
+ arch : ${{ steps.supported-arch-matrix.outputs.platform }}
14
14
steps :
15
15
- uses : actions/checkout@v4
16
+ with :
17
+ sparse-checkout : |
18
+ Dockerfile
16
19
- id : supported-arch-matrix
17
20
name : Generate Arch
18
- run : |
19
- echo "arch=[\"linux/amd64\",\"linux/arm64\"]" >> $GITHUB_OUTPUT
20
- lint-dockerfile :
21
- name : Lint Dockerfile
22
- runs-on : ubuntu-latest
23
- steps :
24
- - uses : actions/checkout@v4
25
- - name : Lint Dockerfile
26
- uses : docker://hadolint/hadolint:latest-debian
27
- with :
28
- entrypoint : hadolint
29
- args : ./Dockerfile
30
- build-docker-image :
31
- name : Build ${{ matrix.platform }} image
32
- strategy :
33
- fail-fast : false
34
- matrix :
35
- platform : ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
36
- needs :
37
- - supported-arch-matrix
38
- - lint-dockerfile
39
- runs-on : ubuntu-latest
40
- steps :
41
- - name : Prepare
42
- run : |
43
- platform=${{ matrix.platform }}
44
- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
45
- - name : Docker meta
46
- id : meta
47
- uses : docker/metadata-action@v5
48
- with :
49
- images : ${{ env.REGISTRY_IMAGE }}
50
- - name : Set up QEMU
51
- uses : docker/setup-qemu-action@v3
52
- - name : Set up Docker Buildx
53
- uses : docker/setup-buildx-action@v3
54
- - uses : actions/checkout@v4
55
- - run : mkdir ./docker-image
56
- - run : docker image build --platform=${{ matrix.platform }} --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` -t "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" --no-cache .
57
- - run : docker save "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" -o ./docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
58
- - uses : actions/upload-artifact@v4
59
- with :
60
- name : docker-image-${{ env.PLATFORM_PAIR }}
61
- path : ./docker-image
62
- scan-vulnerability :
63
- name : Scan for vulnerabilities (${{ matrix.platform }})
64
- strategy :
65
- fail-fast : false
66
- matrix :
67
- platform : ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
68
- needs :
69
- - supported-arch-matrix
70
- - build-docker-image
71
- runs-on : ubuntu-latest
72
- steps :
73
- - name : Prepare
74
- run : |
75
- platform=${{ matrix.platform }}
76
- echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
77
- - uses : actions/checkout@v4
78
- - uses : actions/download-artifact@v4
79
- with :
80
- name : docker-image-${{ env.PLATFORM_PAIR }}
81
- path : /tmp/docker-image
82
- - run : docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
83
- - run : rm -Rf /tmp/docker-image/
84
- - run : echo -e "${{ env.DOCKER_IMAGE }}:${{ env.PLATFORM_PAIR }}" | xargs -I % sh -c 'docker run -v /tmp/trivy:/var/lib/trivy -v /var/run/docker.sock:/var/run/docker.sock -t aquasec/trivy:latest --cache-dir /var/lib/trivy image --exit-code 1 --no-progress --format table % || true'
85
- push-image :
86
- if : (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
87
- name : Push
88
- needs :
89
- - supported-arch-matrix
90
- - scan-vulnerability
91
- runs-on : ubuntu-latest
92
- services :
93
- registry :
94
- image : registry:2
95
- ports :
96
- - 5000:5000
97
- steps :
98
- - name : Get Time
99
- id : time
100
-
101
- with :
102
- format : ' YYYY.MM.DD'
103
- - name : Set up QEMU
104
- uses : docker/setup-qemu-action@v3
105
- - name : Set up Docker Buildx
106
- uses : docker/setup-buildx-action@v3
107
- with :
108
- driver-opts : network=host
109
- - uses : actions/download-artifact@v4
110
- with :
111
- pattern : docker-image-*
112
- path : /tmp/docker-image
113
- merge-multiple : true
114
- - run : ls -lasth /tmp/docker-image/
115
- - run : |
116
- for f in /tmp/docker-image/docker_image-*.tar; do
117
- docker load --input $f
118
- done
119
- - run : rm -Rf /tmp/docker-image/
120
- - run : docker images
121
- - run : |
122
- archs=${{ join(fromJson(needs.supported-arch-matrix.outputs.arch), ',') }}
123
- for arch in ${archs//,/ }
124
- do
125
- docker tag "${{ env.DOCKER_IMAGE }}:${arch//\//-}" "localhost:5000/${{ env.DOCKER_IMAGE }}:${arch//\//-}"
126
- docker push "localhost:5000/${{ env.DOCKER_IMAGE }}:${arch//\//-}"
127
- done
128
- - run : docker images
129
- - name : Login to GitHub Container Registry
130
- if : github.event_name != 'pull_request'
131
- uses : docker/login-action@v3
132
- with :
133
- registry : ghcr.io
134
- username : ${{ github.actor }}
135
- password : ${{ secrets.GHCR_TOKEN }}
136
- - name : Docker info
137
- run : docker info
138
- - name : Create merge Dockerfile
139
- run : echo "FROM localhost:5000/${{ env.DOCKER_IMAGE }}:\${TARGETOS}-\${TARGETARCH}" >> docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
140
- - run : cat docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
141
- - name : Merged different arch images into one
142
- uses : docker/build-push-action@v6
143
- with :
144
- push : ${{ github.event_name != 'pull_request' }}
145
- context : .
146
- file : docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
147
- tags : ghcr.io/${{ env.DOCKER_IMAGE }}:latest,ghcr.io/${{ env.DOCKER_IMAGE }}:${{ steps.time.outputs.time }}
148
- platforms : ${{ join(fromJson(needs.supported-arch-matrix.outputs.arch), ',') }}
21
+ uses : wyrihaximus/github-action-oci-image-supported-archs@initial-implementation
22
+ # run: |
23
+ # echo "arch=[\"linux/amd64\",\"linux/arm64\"]" >> $GITHUB_OUTPUT
24
+ # lint-dockerfile:
25
+ # name: Lint Dockerfile
26
+ # runs-on: ubuntu-latest
27
+ # steps:
28
+ # - uses: actions/checkout@v4
29
+ # - name: Lint Dockerfile
30
+ # uses: docker://hadolint/hadolint:latest-debian
31
+ # with:
32
+ # entrypoint: hadolint
33
+ # args: ./Dockerfile
34
+ # build-docker-image:
35
+ # name: Build ${{ matrix.platform }} image
36
+ # strategy:
37
+ # fail-fast: false
38
+ # matrix:
39
+ # platform: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
40
+ # needs:
41
+ # - supported-arch-matrix
42
+ # - lint-dockerfile
43
+ # runs-on: ubuntu-latest
44
+ # steps:
45
+ # - name: Prepare
46
+ # run: |
47
+ # platform=${{ matrix.platform }}
48
+ # echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
49
+ # - name: Docker meta
50
+ # id: meta
51
+ # uses: docker/metadata-action@v5
52
+ # with:
53
+ # images: ${{ env.REGISTRY_IMAGE }}
54
+ # - name: Set up QEMU
55
+ # uses: docker/setup-qemu-action@v3
56
+ # - name: Set up Docker Buildx
57
+ # uses: docker/setup-buildx-action@v3
58
+ # - uses: actions/checkout@v4
59
+ # - run: mkdir ./docker-image
60
+ # - run: docker image build --platform=${{ matrix.platform }} --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` --build-arg VCS_REF=`git rev-parse --short HEAD` -t "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" --no-cache .
61
+ # - run: docker save "${DOCKER_IMAGE}:${{ env.PLATFORM_PAIR }}" -o ./docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
62
+ # - uses: actions/upload-artifact@v4
63
+ # with:
64
+ # name: docker-image-${{ env.PLATFORM_PAIR }}
65
+ # path: ./docker-image
66
+ # scan-vulnerability:
67
+ # name: Scan for vulnerabilities (${{ matrix.platform }})
68
+ # strategy:
69
+ # fail-fast: false
70
+ # matrix:
71
+ # platform: ${{ fromJson(needs.supported-arch-matrix.outputs.arch) }}
72
+ # needs:
73
+ # - supported-arch-matrix
74
+ # - build-docker-image
75
+ # runs-on: ubuntu-latest
76
+ # steps:
77
+ # - name: Prepare
78
+ # run: |
79
+ # platform=${{ matrix.platform }}
80
+ # echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
81
+ # - uses: actions/checkout@v4
82
+ # - uses: actions/download-artifact@v4
83
+ # with:
84
+ # name: docker-image-${{ env.PLATFORM_PAIR }}
85
+ # path: /tmp/docker-image
86
+ # - run: docker load --input /tmp/docker-image/docker_image-${{ env.PLATFORM_PAIR }}.tar
87
+ # - run: rm -Rf /tmp/docker-image/
88
+ # - run: echo -e "${{ env.DOCKER_IMAGE }}:${{ env.PLATFORM_PAIR }}" | xargs -I % sh -c 'docker run -v /tmp/trivy:/var/lib/trivy -v /var/run/docker.sock:/var/run/docker.sock -t aquasec/trivy:latest --cache-dir /var/lib/trivy image --exit-code 1 --no-progress --format table % || true'
89
+ # push-image:
90
+ # if: (github.event_name == 'push' || github.event_name == 'schedule') && github.ref == 'refs/heads/master'
91
+ # name: Push
92
+ # needs:
93
+ # - supported-arch-matrix
94
+ # - scan-vulnerability
95
+ # runs-on: ubuntu-latest
96
+ # services:
97
+ # registry:
98
+ # image: registry:2
99
+ # ports:
100
+ # - 5000:5000
101
+ # steps:
102
+ # - name: Get Time
103
+ # id: time
104
+
105
+ # with:
106
+ # format: 'YYYY.MM.DD'
107
+ # - name: Set up QEMU
108
+ # uses: docker/setup-qemu-action@v3
109
+ # - name: Set up Docker Buildx
110
+ # uses: docker/setup-buildx-action@v3
111
+ # with:
112
+ # driver-opts: network=host
113
+ # - uses: actions/download-artifact@v4
114
+ # with:
115
+ # pattern: docker-image-*
116
+ # path: /tmp/docker-image
117
+ # merge-multiple: true
118
+ # - run: ls -lasth /tmp/docker-image/
119
+ # - run: |
120
+ # for f in /tmp/docker-image/docker_image-*.tar; do
121
+ # docker load --input $f
122
+ # done
123
+ # - run: rm -Rf /tmp/docker-image/
124
+ # - run: docker images
125
+ # - run: |
126
+ # archs=${{ join(fromJson(needs.supported-arch-matrix.outputs.arch), ',') }}
127
+ # for arch in ${archs//,/ }
128
+ # do
129
+ # docker tag "${{ env.DOCKER_IMAGE }}:${arch//\//-}" "localhost:5000/${{ env.DOCKER_IMAGE }}:${arch//\//-}"
130
+ # docker push "localhost:5000/${{ env.DOCKER_IMAGE }}:${arch//\//-}"
131
+ # done
132
+ # - run: docker images
133
+ # - name: Login to GitHub Container Registry
134
+ # if: github.event_name != 'pull_request'
135
+ # uses: docker/login-action@v3
136
+ # with:
137
+ # registry: ghcr.io
138
+ # username: ${{ github.actor }}
139
+ # password: ${{ secrets.GHCR_TOKEN }}
140
+ # - name: Docker info
141
+ # run: docker info
142
+ # - name: Create merge Dockerfile
143
+ # run: echo "FROM localhost:5000/${{ env.DOCKER_IMAGE }}:\${TARGETOS}-\${TARGETARCH}" >> docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
144
+ # - run: cat docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
145
+ # - name: Merged different arch images into one
146
+ # uses: docker/build-push-action@v6
147
+ # with:
148
+ # push: ${{ github.event_name != 'pull_request' }}
149
+ # context: .
150
+ # file: docker-file-${{ matrix.registry }}-wyrihaximusnet-github-action-runner
151
+ # tags: ghcr.io/${{ env.DOCKER_IMAGE }}:latest,ghcr.io/${{ env.DOCKER_IMAGE }}:${{ steps.time.outputs.time }}
152
+ # platforms: ${{ join(fromJson(needs.supported-arch-matrix.outputs.arch), ',') }}
0 commit comments