|
1 | 1 | name: Build and push docker image |
| 2 | +'on': |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + publish_image: |
| 6 | + required: true |
| 7 | + type: boolean |
| 8 | +jobs: |
| 9 | + build_image: |
| 10 | + permissions: |
| 11 | + id-token: write |
| 12 | + runs-on: '${{ matrix.runner }}' |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - arch: amd64 |
| 17 | + runner: ubuntu-22.04 |
| 18 | + - arch: arm64 |
| 19 | + runner: ubuntu-22.04-arm |
| 20 | + steps: |
| 21 | + - name: Checkout code |
| 22 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 |
| 23 | + with: |
| 24 | + fetch-depth: 0 |
| 25 | + - name: setup node |
| 26 | + uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f |
| 27 | + with: |
| 28 | + node-version-file: .tool-versions |
| 29 | + - name: make install |
| 30 | + run: | |
| 31 | + make install-node |
| 32 | + - name: Build container |
| 33 | + run: > |
| 34 | + make build-base-image |
2 | 35 |
|
3 | | -on: |
4 | | - workflow_call: |
| 36 | + docker tag ghcr.io/nhsdigital/eps-devcontainer-base:latest "ghcr.io/nhsdigital/eps-devcontainers:latest-${ARCHITECTURE}" |
5 | 37 |
|
6 | | -jobs: |
| 38 | + docker save "ghcr.io/nhsdigital/eps-devcontainers:latest-${ARCHITECTURE}" -o "eps-devcontainer-base-latest-${ARCHITECTURE}.img" |
| 39 | + env: |
| 40 | + GH_TOKEN: '${{ github.token }}' |
| 41 | + ARCHITECTURE: '${{ matrix.arch }}' |
| 42 | + - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f |
| 43 | + name: Upload docker images |
| 44 | + with: |
| 45 | + name: "eps-devcontainer-base-latest-${{ matrix.arch }}.img" |
| 46 | + path: | |
| 47 | + eps-devcontainer-base-latest-${{ matrix.arch }}.img |
| 48 | + - name: Check docker vulnerabilities |
| 49 | + uses: aquasecurity/trivy-action@b6643a29fecd7f34b3597bc6acb0a98b03d33ff8 |
| 50 | + with: |
| 51 | + scan-type: "image" |
| 52 | + image-ref: "ghcr.io/nhsdigital/eps-devcontainers:latest-${{ matrix.arch }}" |
| 53 | + severity: "CRITICAL,HIGH" |
| 54 | + scanners: "vuln" |
| 55 | + vuln-type: "os,library" |
| 56 | + format: "table" |
| 57 | + output: "dependency_results_docker.txt" |
| 58 | + exit-code: "1" |
| 59 | + trivy-config: trivy.yaml |
| 60 | + |
| 61 | + - name: Show docker vulnerability output |
| 62 | + if: always() |
| 63 | + run: | |
| 64 | + echo "Scan output for ghcr.io/nhsdigital/eps-devcontainers:latest-${ARCHITECTURE}" |
| 65 | + if [ -f dependency_results_docker.txt ]; then |
| 66 | + cat dependency_results_docker.txt |
| 67 | + fi |
| 68 | + env: |
| 69 | + ARCHITECTURE: '${{ matrix.arch }}' |
| 70 | + |
| 71 | + publish_image: |
| 72 | + needs: build_image |
| 73 | + runs-on: ubuntu-22.04 |
| 74 | + if: ${{ inputs.publish_image }} |
| 75 | + permissions: |
| 76 | + contents: read |
| 77 | + packages: write |
| 78 | + attestations: write |
| 79 | + id-token: write |
| 80 | + steps: |
| 81 | + - name: Free Disk Space for Docker |
| 82 | + uses: >- |
| 83 | + endersonmenezes/free-disk-space@e6ed9b02e683a3b55ed0252f1ee469ce3b39a885 |
| 84 | + with: |
| 85 | + remove_android: true |
| 86 | + remove_dotnet: true |
| 87 | + remove_haskell: true |
| 88 | + remove_tool_cache: true |
| 89 | + rm_cmd: rm |
| 90 | + remove_packages: >- |
| 91 | + azure-cli google-cloud-cli microsoft-edge-stable |
| 92 | + google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* |
| 93 | + dotnet-sdk-* |
| 94 | + remove_packages_one_command: true |
| 95 | + - name: Download amd64 images |
| 96 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 |
| 97 | + with: |
| 98 | + name: eps-devcontainer-base-latest-amd64.img |
| 99 | + - name: Download arm64 images |
| 100 | + uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 |
| 101 | + with: |
| 102 | + name: eps-devcontainer-base-latest-arm64.img |
| 103 | + - name: Load and push multi-arch image |
| 104 | + run: > |
| 105 | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ |
| 106 | + github.actor }} --password-stdin |
| 107 | +
|
| 108 | + echo "loading images" |
| 109 | +
|
| 110 | + docker load -i eps-devcontainer-base-latest-amd64.img |
| 111 | +
|
| 112 | + docker load -i eps-devcontainer-base-latest-arm64.img |
| 113 | +
|
| 114 | + echo "pushing images" |
| 115 | +
|
| 116 | + docker push ghcr.io/nhsdigital/eps-devcontainers:latest-amd64 |
7 | 117 |
|
8 | | - build_image: |
9 | | - permissions: |
10 | | - id-token: write |
11 | | - runs-on: ${{ matrix.runner }} |
12 | | - strategy: |
13 | | - matrix: |
14 | | - include: |
15 | | - - arch: amd64 |
16 | | - runner: ubuntu-22.04 |
17 | | - - arch: arm64 |
18 | | - runner: ubuntu-22.04-arm |
19 | | - steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 |
22 | | - with: |
23 | | - fetch-depth: 0 |
| 118 | + docker push ghcr.io/nhsdigital/eps-devcontainers:latest-arm64 |
24 | 119 |
|
25 | | - # use setup-node rather than asdf so that it works multi-arch |
26 | | - - name: setup node |
27 | | - uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f |
28 | | - with: |
29 | | - node-version-file: .tool-versions |
30 | | - - name: make install |
31 | | - run: | |
32 | | - make install-node |
| 120 | + echo "creating manifest" |
33 | 121 |
|
34 | | - - name: Build container |
35 | | - run: | |
36 | | - make build-base-image |
37 | | - docker tag ghcr.io/nhsdigital/eps-devcontainer-base:latest ghcr.io/nhsdigital/eps-devcontainers:latest-${{ matrix.arch }} |
38 | | - docker save "ghcr.io/nhsdigital/eps-devcontainers:latest-${{ matrix.arch }}" -o eps-devcontainer-base-latest-${{ matrix.arch }}.img |
39 | | - env: |
40 | | - GH_TOKEN: ${{ github.token }} |
41 | | - ARCHITECTURE: ${{ matrix.arch }} |
42 | | - - uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f |
43 | | - name: Upload docker images |
44 | | - with: |
45 | | - name: eps-devcontainer-base-latest-${{ matrix.arch }}.img |
46 | | - path: | |
47 | | - eps-devcontainer-base-latest-${{ matrix.arch }}.img |
| 122 | + docker manifest create ghcr.io/nhsdigital/eps-devcontainers:latest \ |
| 123 | + --amend ghcr.io/nhsdigital/eps-devcontainers:latest-amd64 \ |
| 124 | + --amend ghcr.io/nhsdigital/eps-devcontainers:latest-arm64 |
| 125 | + echo "pushing manifest" |
48 | 126 |
|
49 | | - publish_image: |
50 | | - needs: build_image |
51 | | - runs-on: ubuntu-22.04 |
52 | | - permissions: |
53 | | - contents: read |
54 | | - packages: write |
55 | | - attestations: write |
56 | | - id-token: write |
57 | | - steps: |
58 | | - - name: Free Disk Space for Docker |
59 | | - uses: endersonmenezes/free-disk-space@e6ed9b02e683a3b55ed0252f1ee469ce3b39a885 |
60 | | - with: |
61 | | - remove_android: true |
62 | | - remove_dotnet: true |
63 | | - remove_haskell: true |
64 | | - remove_tool_cache: true |
65 | | - rm_cmd: "rm" |
66 | | - remove_packages: "azure-cli google-cloud-cli microsoft-edge-stable google-chrome-stable firefox postgresql* temurin-* *llvm* mysql* dotnet-sdk-*" |
67 | | - remove_packages_one_command: true |
68 | | - - name: Download amd64 images |
69 | | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 |
70 | | - with: |
71 | | - name: eps-devcontainer-base-latest-amd64.img |
72 | | - - name: Download arm64 images |
73 | | - uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131 |
74 | | - with: |
75 | | - name: eps-devcontainer-base-latest-arm64.img |
76 | | - - name: Load and push multi-arch image |
77 | | - run: | |
78 | | - echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin |
79 | | - echo "loading images" |
80 | | - docker load -i eps-devcontainer-base-latest-amd64.img |
81 | | - docker load -i eps-devcontainer-base-latest-arm64.img |
82 | | - echo "pushing images" |
83 | | - docker push ghcr.io/nhsdigital/eps-devcontainers:latest-amd64 |
84 | | - docker push ghcr.io/nhsdigital/eps-devcontainers:latest-arm64 |
85 | | - echo "creating manifest" |
86 | | - docker manifest create ghcr.io/nhsdigital/eps-devcontainers:latest \ |
87 | | - --amend ghcr.io/nhsdigital/eps-devcontainers:latest-amd64 \ |
88 | | - --amend ghcr.io/nhsdigital/eps-devcontainers:latest-arm64 |
89 | | - echo "pushing manifest" |
90 | | - docker manifest push ghcr.io/nhsdigital/eps-devcontainers:latest |
| 127 | + docker manifest push ghcr.io/nhsdigital/eps-devcontainers:latest |
0 commit comments