|
18 | 18 | - '.github/workflows/containers/github-action-ci/**' |
19 | 19 |
|
20 | 20 | jobs: |
21 | | - # TODO(boomanaiden154): Switch this back to a single stage build when we can |
22 | | - # run this on the self-hosted runners and don't have to do it this way to |
23 | | - # avoid timeouts. |
24 | | - build-ci-container-stage1: |
| 21 | + build-ci-container: |
25 | 22 | if: github.repository_owner == 'llvm' |
26 | | - runs-on: ubuntu-latest |
| 23 | + runs-on: depot-ubuntu-22.04-16 |
| 24 | + outputs: |
| 25 | + container-name: ${{ steps.vars.outputs.container-name }} |
| 26 | + container-name-tag: ${{ steps.vars.outputs.container-name-tag }} |
| 27 | + container-filename: ${{ steps.vars.outputs.container-filename }} |
27 | 28 | steps: |
28 | 29 | - name: Checkout LLVM |
29 | 30 | uses: actions/checkout@v4 |
30 | 31 | with: |
31 | 32 | sparse-checkout: .github/workflows/containers/github-action-ci/ |
32 | | - - name: Change podman Root Direcotry |
33 | | - run: | |
34 | | - mkdir -p ~/.config/containers |
35 | | - sudo mkdir -p /mnt/podman |
36 | | - sudo chown `whoami`:`whoami` /mnt/podman |
37 | | - cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf |
38 | | - podman info |
39 | | - - name: Build container stage1 |
40 | | - working-directory: ./.github/workflows/containers/github-action-ci/ |
41 | | - run: | |
42 | | - podman build -t stage1-toolchain --target stage1-toolchain -f stage1.Dockerfile . |
43 | | - - name: Save container image |
44 | | - run: | |
45 | | - podman save stage1-toolchain > stage1-toolchain.tar |
46 | | - - name: Upload container image |
47 | | - uses: actions/upload-artifact@v4 |
48 | | - with: |
49 | | - name: stage1-toolchain |
50 | | - path: stage1-toolchain.tar |
51 | | - retention-days: 1 |
52 | | - build-ci-container-stage2: |
53 | | - if: github.repository_owner == 'llvm' |
54 | | - runs-on: ubuntu-latest |
55 | | - needs: build-ci-container-stage1 |
56 | | - permissions: |
57 | | - packages: write |
58 | | - steps: |
59 | 33 | - name: Write Variables |
60 | 34 | id: vars |
61 | 35 | run: | |
62 | 36 | tag=`date +%s` |
63 | 37 | container_name="ghcr.io/$GITHUB_REPOSITORY_OWNER/ci-ubuntu-22.04" |
64 | 38 | echo "container-name=$container_name" >> $GITHUB_OUTPUT |
65 | 39 | echo "container-name-tag=$container_name:$tag" >> $GITHUB_OUTPUT |
66 | | -
|
67 | | - - name: Checkout LLVM |
68 | | - uses: actions/checkout@v4 |
69 | | - with: |
70 | | - sparse-checkout: .github/workflows/containers/github-action-ci/ |
71 | | - |
72 | | - - name: Change podman Root Direcotry |
| 40 | + echo "container-filename=$(echo $container_name:$tag | sed -e 's/\//-/g' -e 's/:/-/g').tar" >> $GITHUB_OUTPUT |
| 41 | + - name: Build container |
| 42 | + working-directory: ./.github/workflows/containers/github-action-ci/ |
73 | 43 | run: | |
74 | | - mkdir -p ~/.config/containers |
75 | | - sudo mkdir -p /mnt/podman |
76 | | - sudo chown `whoami`:`whoami` /mnt/podman |
77 | | - cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf |
78 | | - podman info |
| 44 | + podman build -t ${{ steps.vars.outputs.container-name-tag }} . |
79 | 45 |
|
80 | | - # Download the container image into /mnt/podman rather than |
81 | | - # $GITHUB_WORKSPACE to avoid space limitations on the default drive |
82 | | - # and use the permissions setup for /mnt/podman. |
83 | | - - name: Download stage1-toolchain |
84 | | - uses: actions/download-artifact@v4 |
85 | | - with: |
86 | | - name: stage1-toolchain |
87 | | - path: /mnt/podman |
88 | | - |
89 | | - - name: Load stage1-toolchain |
| 46 | + # Save the container so we have it in case the push fails. This also |
| 47 | + # allows us to separate the push step into a different job so we can |
| 48 | + # maintain minimal permissions while building the container. |
| 49 | + - name: Save container image |
90 | 50 | run: | |
91 | | - podman load -i /mnt/podman/stage1-toolchain.tar |
| 51 | + podman save ${{ steps.vars.outputs.container-name-tag }} > ${{ steps.vars.outputs.container-filename }} |
92 | 52 |
|
93 | | - - name: Build Container |
94 | | - working-directory: ./.github/workflows/containers/github-action-ci/ |
95 | | - run: | |
96 | | - podman build -t ${{ steps.vars.outputs.container-name-tag }} -f stage2.Dockerfile . |
97 | | - podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest |
| 53 | + - name: Upload container image |
| 54 | + uses: actions/upload-artifact@v4 |
| 55 | + with: |
| 56 | + name: container |
| 57 | + path: ${{ steps.vars.outputs.container-filename }} |
| 58 | + retention-days: 14 |
98 | 59 |
|
99 | 60 | - name: Test Container |
100 | 61 | run: | |
101 | 62 | for image in ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}; do |
102 | 63 | podman run --rm -it $image /usr/bin/bash -x -c 'printf '\''#include <iostream>\nint main(int argc, char **argv) { std::cout << "Hello\\n"; }'\'' | clang++ -x c++ - && ./a.out | grep Hello' |
103 | 64 | done |
104 | 65 |
|
| 66 | + push-ci-container: |
| 67 | + if: github.event_name == 'push' |
| 68 | + needs: |
| 69 | + - build-ci-container |
| 70 | + permissions: |
| 71 | + packages: write |
| 72 | + runs-on: ubuntu-24.04 |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + steps: |
| 76 | + - name: Download container |
| 77 | + uses: actions/download-artifact@v4 |
| 78 | + with: |
| 79 | + name: container |
| 80 | + |
105 | 81 | - name: Push Container |
106 | | - if: github.event_name == 'push' |
107 | | - env: |
108 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
109 | 82 | run: | |
| 83 | + podman load -i ${{ needs.build-ci-container.outptus.container-filename }} |
| 84 | + podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest |
110 | 85 | podman login -u ${{ github.actor }} -p $GITHUB_TOKEN ghcr.io |
111 | | - podman push ${{ steps.vars.outputs.container-name-tag }} |
112 | | - podman push ${{ steps.vars.outputs.container-name }}:latest |
| 86 | + podman push ${{ needs.build-ci-container.outputs.container-name-tag }} |
| 87 | + podman push ${{ needs.build-ci-container.outputs.container-name }}:latest |
0 commit comments