|
1 | 1 | name: docker |
2 | 2 |
|
3 | 3 | on: |
4 | | - push: |
5 | | - tags: |
6 | | - - "v*.*.*" |
7 | | - schedule: |
8 | | - - cron: "0 0 * * *" |
9 | | - # Trigger without any parameters a proactive rebuild |
10 | | - workflow_dispatch: {} |
11 | | - workflow_call: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*.*.*" |
| 7 | + schedule: |
| 8 | + - cron: "0 0 * * *" |
| 9 | + # Trigger without any parameters a proactive rebuild |
| 10 | + workflow_dispatch: {} |
| 11 | + workflow_call: |
12 | 12 |
|
13 | 13 | env: |
14 | | - REGISTRY: ghcr.io |
15 | | - # Will resolve to foundry-rs/foundry |
16 | | - IMAGE_NAME: ${{ github.repository }} |
| 14 | + REGISTRY: ghcr.io |
| 15 | + # Will resolve to foundry-rs/foundry |
| 16 | + IMAGE_NAME: ${{ github.repository }} |
17 | 17 |
|
18 | 18 | jobs: |
19 | | - container: |
20 | | - runs-on: Linux-20.04 |
21 | | - # https://docs.github.com/en/actions/reference/authentication-in-a-workflow |
22 | | - permissions: |
23 | | - id-token: write |
24 | | - packages: write |
25 | | - contents: read |
26 | | - timeout-minutes: 120 |
27 | | - steps: |
28 | | - - name: Checkout repository |
29 | | - id: checkout |
30 | | - uses: actions/checkout@v4 |
| 19 | + build: |
| 20 | + name: build and push |
| 21 | + runs-on: Linux-20.04 |
| 22 | + permissions: |
| 23 | + id-token: write |
| 24 | + packages: write |
| 25 | + contents: read |
| 26 | + timeout-minutes: 120 |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + - uses: dtolnay/rust-toolchain@stable |
| 30 | + - uses: Swatinem/rust-cache@v2 |
| 31 | + with: |
| 32 | + cache-on-failure: true |
| 33 | + - uses: taiki-e/install-action@cross |
| 34 | + # Login against a Docker registry except on PR |
| 35 | + # https://github.com/docker/login-action |
| 36 | + - name: Login into registry ${{ env.REGISTRY }} |
| 37 | + # Ensure this doesn't trigger on PR's |
| 38 | + if: github.event_name != 'pull_request' |
| 39 | + uses: docker/login-action@v2 |
| 40 | + with: |
| 41 | + registry: ${{ env.REGISTRY }} |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
31 | 44 |
|
32 | | - - name: Install Docker BuildX |
33 | | - uses: docker/setup-buildx-action@v2 |
34 | | - id: buildx |
35 | | - with: |
36 | | - install: true |
| 45 | + # Extract metadata (tags, labels) for Docker |
| 46 | + # https://github.com/docker/metadata-action |
| 47 | + - name: Extract Docker metadata |
| 48 | + id: meta |
| 49 | + uses: docker/metadata-action@v4 |
| 50 | + with: |
| 51 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
37 | 52 |
|
38 | | - # Login against a Docker registry except on PR |
39 | | - # https://github.com/docker/login-action |
40 | | - - name: Log into registry ${{ env.REGISTRY }} |
41 | | - # Ensure this doesn't trigger on PR's |
42 | | - if: github.event_name != 'pull_request' |
43 | | - uses: docker/login-action@v2 |
44 | | - with: |
45 | | - registry: ${{ env.REGISTRY }} |
46 | | - username: ${{ github.actor }} |
47 | | - password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + # Creates an additional 'latest' or 'nightly' tag |
| 54 | + # If the job is triggered via cron schedule, tag nightly and nightly-{SHA} |
| 55 | + # If the job is triggered via workflow dispatch and on a master branch, tag branch and latest |
| 56 | + # Otherwise, just tag as the branch name |
| 57 | + - name: Finalize Docker Metadata |
| 58 | + id: docker_tagging |
| 59 | + run: | |
| 60 | + if [[ "${{ github.event_name }}" == 'schedule' ]]; then |
| 61 | + echo "cron trigger, assigning nightly tag" |
| 62 | + echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly-${GITHUB_SHA}" >> $GITHUB_OUTPUT |
| 63 | + elif [[ "${GITHUB_REF##*/}" == "main" ]] || [[ ${GITHUB_REF##*/} == "master" ]]; then |
| 64 | + echo "manual trigger from master/main branch, assigning latest tag" |
| 65 | + echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT |
| 66 | + else |
| 67 | + echo "Neither scheduled nor manual release from main branch. Just tagging as branch name" |
| 68 | + echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" >> $GITHUB_OUTPUT |
| 69 | + fi |
48 | 70 |
|
49 | | - # Extract metadata (tags, labels) for Docker |
50 | | - # https://github.com/docker/metadata-action |
51 | | - - name: Extract Docker metadata |
52 | | - id: meta |
53 | | - uses: docker/metadata-action@v4 |
54 | | - with: |
55 | | - images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 71 | + # Log docker metadata to explicitly know what is being pushed |
| 72 | + - name: Inspect Docker Metadata |
| 73 | + run: | |
| 74 | + echo "TAGS -> ${{ steps.docker_tagging.outputs.docker_tags }}" |
| 75 | + echo "LABELS -> ${{ steps.meta.outputs.labels }}" |
56 | 76 |
|
57 | | - # Creates an additional 'latest' or 'nightly' tag |
58 | | - # If the job is triggered via cron schedule, tag nightly and nightly-{SHA} |
59 | | - # If the job is triggered via workflow dispatch and on a master branch, tag branch and latest |
60 | | - # Otherwise, just tag as the branch name |
61 | | - - name: Finalize Docker Metadata |
62 | | - id: docker_tagging |
63 | | - run: | |
64 | | - if [[ "${{ github.event_name }}" == 'schedule' ]]; then |
65 | | - echo "cron trigger, assigning nightly tag" |
66 | | - echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly-${GITHUB_SHA}" >> $GITHUB_OUTPUT |
67 | | - elif [[ "${GITHUB_REF##*/}" == "main" ]] || [[ ${GITHUB_REF##*/} == "master" ]]; then |
68 | | - echo "manual trigger from master/main branch, assigning latest tag" |
69 | | - echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/},${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest" >> $GITHUB_OUTPUT |
70 | | - else |
71 | | - echo "Neither scheduled nor manual release from main branch. Just tagging as branch name" |
72 | | - echo "docker_tags=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${GITHUB_REF##*/}" >> $GITHUB_OUTPUT |
73 | | - fi |
74 | | -
|
75 | | - # Log docker metadata to explicitly know what is being pushed |
76 | | - - name: Inspect Docker Metadata |
77 | | - run: | |
78 | | - echo "TAGS -> ${{ steps.docker_tagging.outputs.docker_tags }}" |
79 | | - echo "LABELS -> ${{ steps.meta.outputs.labels }}" |
80 | | -
|
81 | | - # Build and push Docker image |
82 | | - # https://github.com/docker/build-push-action |
83 | | - # https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md |
84 | | - - name: Build and push Docker image |
85 | | - uses: docker/build-push-action@v3 |
86 | | - with: |
87 | | - context: . |
88 | | - push: true |
89 | | - tags: ${{ steps.docker_tagging.outputs.docker_tags }} |
90 | | - labels: ${{ steps.meta.outputs.labels }} |
91 | | - cache-from: type=gha |
92 | | - cache-to: type=gha,mode=max |
93 | | - build-args: | |
94 | | - BUILDTIME=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }} |
95 | | - VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }} |
96 | | - REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }} |
| 77 | + - name: Build and push foundry image |
| 78 | + run: make DOCKER_IMAGE_NAME=${{ steps.docker_tagging.outputs.docker_tags }} PROFILE=maxperf docker-build-push |
0 commit comments