|
1 | 1 | name: Build and push docker image to ghcr
|
2 | 2 |
|
3 | 3 | on:
|
4 |
| - workflow_dispatch: |
5 |
| - push: |
6 |
| - branches: |
7 |
| - - 'main' |
8 |
| - tags: |
9 |
| - - 'v*' |
| 4 | + workflow_dispatch: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - "main" |
| 8 | + - "otel-v2" |
| 9 | + tags: |
| 10 | + - "v*" |
10 | 11 |
|
11 | 12 | jobs:
|
12 |
| - build-and-push-image: |
13 |
| - concurrency: |
14 |
| - group: ${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.run_id }} |
15 |
| - cancel-in-progress: true |
16 |
| - runs-on: a100-runner |
17 |
| - permissions: |
18 |
| - contents: write |
19 |
| - packages: write |
20 |
| - # This is used to complete the identity challenge |
21 |
| - # with sigstore/fulcio when running outside of PRs. |
22 |
| - id-token: write |
23 |
| - security-events: write |
24 |
| - |
25 |
| - steps: |
26 |
| - - name: Log in to GitHub Container Registry |
27 |
| - uses: docker/login-action@v1 |
28 |
| - with: |
29 |
| - registry: ghcr.io |
30 |
| - username: ${{ github.repository_owner }} |
31 |
| - password: ${{ secrets.GHCR_PAT }} |
32 |
| - |
33 |
| - - name: Checkout repository |
34 |
| - uses: actions/checkout@v3 |
35 |
| - with: |
36 |
| - submodules: recursive |
37 |
| - |
38 |
| - - name: Free Disk Space (Ubuntu) |
39 |
| - uses: jlumbroso/free-disk-space@main |
40 |
| - with: |
41 |
| - tool-cache: false |
42 |
| - android: true |
43 |
| - dotnet: true |
44 |
| - haskell: true |
45 |
| - large-packages: false |
46 |
| - swap-storage: true |
47 |
| - |
48 |
| - - name: Install soci |
49 |
| - |
50 |
| - with: |
51 |
| - soci-release: 'v0.4.0' |
52 |
| - |
53 |
| - - name: Set up Docker Buildx |
54 |
| - |
55 |
| - |
56 |
| - - name: Set up containerd for ubuntu |
57 |
| - |
58 |
| - with: |
59 |
| - config-inline: | |
60 |
| - version = 2 |
61 |
| -
|
62 |
| - # persistent data location |
63 |
| - root = "/runner/build/containerd" |
64 |
| -
|
65 |
| - - name: Docker meta |
66 |
| - id: meta |
67 |
| - uses: docker/metadata-action@v5 |
68 |
| - with: |
69 |
| - images: | |
70 |
| - ghcr.io/predibase/lorax |
71 |
| - tags: | |
72 |
| - type=semver,pattern={{version}} |
73 |
| - type=semver,pattern={{major}}.{{minor}} |
74 |
| - type=sha,prefix=,suffix=,format=short |
75 |
| - type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }} |
76 |
| -
|
77 |
| - - name: Create a hash from tags |
78 |
| - env: |
79 |
| - tags: ${{ steps.meta.outputs.tags }} |
80 |
| - id: vars |
81 |
| - run: | |
82 |
| - tag_hash=$(echo -n "$tags" | md5sum | awk '{print $1}') |
83 |
| - echo "tag_hash=$tag_hash" >> $GITHUB_OUTPUT |
84 |
| - echo "cache_dir=/runner/build/images/cache" >> $GITHUB_OUTPUT |
85 |
| - echo "image_dir=/runner/build/images" >> $GITHUB_OUTPUT |
86 |
| - echo "image_path=/runner/build/images/lorax" >> $GITHUB_OUTPUT |
87 |
| -
|
88 |
| - - name: Create and update image/cache directory |
89 |
| - env: |
90 |
| - image_dir: ${{ steps.vars.outputs.image_dir }} |
91 |
| - cache_dir: ${{ steps.vars.outputs.cache_dir }} |
92 |
| - run: | |
93 |
| - sudo mkdir -p $image_dir |
94 |
| - sudo chown ubuntu:ubuntu $image_dir |
95 |
| -
|
96 |
| - sudo mkdir -p $cache_dir |
97 |
| - sudo chown ubuntu:ubuntu $cache_dir |
98 |
| -
|
99 |
| - - name: Export Docker image as OCI |
100 |
| - uses: docker/build-push-action@v5 |
101 |
| - with: |
102 |
| - context: . |
103 |
| - file: ./Dockerfile # Path to your Dockerfile |
104 |
| - push: false |
105 |
| - tags: ${{ steps.meta.outputs.tags }} |
106 |
| - outputs: type=oci,compression=gzip,dest=${{ steps.vars.outputs.image_path }}-${{ steps.vars.outputs.tag_hash }}.tar.gz |
107 |
| - cache-from: type=local,src=${{ steps.vars.outputs.cache_dir }} |
108 |
| - cache-to: type=local,mode=max,image-manifest=true,oci-mediatypes=true,dest=${{ steps.vars.outputs.cache_dir }} |
109 |
| - |
110 |
| - - name: Import image in containerd |
111 |
| - env: |
112 |
| - tag_hash: ${{ steps.vars.outputs.tag_hash }} |
113 |
| - image_path: ${{ steps.vars.outputs.image_path }} |
114 |
| - run: | |
115 |
| - echo "Importing $image_path-$tag_hash to Containerd" |
116 |
| - sudo ctr i import --no-unpack --all-platforms --digests $image_path-$tag_hash.tar.gz |
117 |
| -
|
118 |
| - - name: Push image with containerd |
119 |
| - env: |
120 |
| - tags: ${{ steps.meta.outputs.tags }} |
121 |
| - run: | |
122 |
| - for tag in $tags |
123 |
| - do |
124 |
| - echo "Pushing $tag to GHCR" |
125 |
| - sudo ctr i push --user "${{ github.repository_owner }}:${{ secrets.GHCR_PAT }}" $tag |
126 |
| - done |
127 |
| -
|
128 |
| - - name: Create and push soci index |
129 |
| - env: |
130 |
| - tags: ${{ steps.meta.outputs.tags }} |
131 |
| - run: | |
132 |
| - export SOCI_PATH=$HOME/.soci/soci |
133 |
| - for tag in $tags |
134 |
| - do |
135 |
| - echo "Creating soci index for $tag" |
136 |
| - sudo $SOCI_PATH create $tag |
137 |
| - echo "Pushing soci index for $tag" |
138 |
| - sudo $SOCI_PATH push --user ${{ github.repository_owner }}:${{ secrets.GHCR_PAT }} $tag |
139 |
| - done |
140 |
| -
|
141 |
| - - name: Prune older images |
142 |
| - env: |
143 |
| - tag_hash: ${{ steps.vars.outputs.tag_hash }} |
144 |
| - image_path: ${{ steps.vars.outputs.image_path }} |
145 |
| - run: | |
146 |
| - # Delete images older than a day from docker store |
147 |
| - docker image prune -a -f --filter "until=24h" |
148 |
| -
|
149 |
| - # Delete the on disk copy |
150 |
| - rm -rf "$image_path-$tag_hash.tar.gz" |
151 |
| -
|
152 |
| - # Delete the SHA image(s) from containerd store |
153 |
| - sudo ctr i rm $(sudo ctr i ls -q) |
| 13 | + build-and-push-image: |
| 14 | + concurrency: |
| 15 | + group: ${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.run_id }} |
| 16 | + cancel-in-progress: true |
| 17 | + runs-on: a100-runner |
| 18 | + permissions: |
| 19 | + contents: write |
| 20 | + packages: write |
| 21 | + # This is used to complete the identity challenge |
| 22 | + # with sigstore/fulcio when running outside of PRs. |
| 23 | + id-token: write |
| 24 | + security-events: write |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Log in to GitHub Container Registry |
| 28 | + uses: docker/login-action@v1 |
| 29 | + with: |
| 30 | + registry: ghcr.io |
| 31 | + username: ${{ github.repository_owner }} |
| 32 | + password: ${{ secrets.GHCR_PAT }} |
| 33 | + |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v3 |
| 36 | + with: |
| 37 | + submodules: recursive |
| 38 | + |
| 39 | + - name: Free Disk Space (Ubuntu) |
| 40 | + uses: jlumbroso/free-disk-space@main |
| 41 | + with: |
| 42 | + tool-cache: false |
| 43 | + android: true |
| 44 | + dotnet: true |
| 45 | + haskell: true |
| 46 | + large-packages: false |
| 47 | + swap-storage: true |
| 48 | + |
| 49 | + - name: Install soci |
| 50 | + |
| 51 | + with: |
| 52 | + soci-release: "v0.4.0" |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + |
| 56 | + |
| 57 | + - name: Set up containerd for ubuntu |
| 58 | + |
| 59 | + with: |
| 60 | + config-inline: | |
| 61 | + version = 2 |
| 62 | +
|
| 63 | + # persistent data location |
| 64 | + root = "/runner/build/containerd" |
| 65 | +
|
| 66 | + - name: Docker meta |
| 67 | + id: meta |
| 68 | + uses: docker/metadata-action@v5 |
| 69 | + with: |
| 70 | + images: | |
| 71 | + ghcr.io/predibase/lorax |
| 72 | + tags: | |
| 73 | + type=semver,pattern={{version}} |
| 74 | + type=semver,pattern={{major}}.{{minor}} |
| 75 | + type=sha,prefix=,suffix=,format=short |
| 76 | + type=raw,value=main,enable=${{ github.ref == 'refs/heads/main' }} |
| 77 | +
|
| 78 | + - name: Create a hash from tags |
| 79 | + env: |
| 80 | + tags: ${{ steps.meta.outputs.tags }} |
| 81 | + id: vars |
| 82 | + run: | |
| 83 | + tag_hash=$(echo -n "$tags" | md5sum | awk '{print $1}') |
| 84 | + echo "tag_hash=$tag_hash" >> $GITHUB_OUTPUT |
| 85 | + echo "cache_dir=/runner/build/images/cache" >> $GITHUB_OUTPUT |
| 86 | + echo "image_dir=/runner/build/images" >> $GITHUB_OUTPUT |
| 87 | + echo "image_path=/runner/build/images/lorax" >> $GITHUB_OUTPUT |
| 88 | +
|
| 89 | + - name: Create and update image/cache directory |
| 90 | + env: |
| 91 | + image_dir: ${{ steps.vars.outputs.image_dir }} |
| 92 | + cache_dir: ${{ steps.vars.outputs.cache_dir }} |
| 93 | + run: | |
| 94 | + sudo mkdir -p $image_dir |
| 95 | + sudo chown ubuntu:ubuntu $image_dir |
| 96 | +
|
| 97 | + sudo mkdir -p $cache_dir |
| 98 | + sudo chown ubuntu:ubuntu $cache_dir |
| 99 | +
|
| 100 | + - name: Export Docker image as OCI |
| 101 | + uses: docker/build-push-action@v5 |
| 102 | + with: |
| 103 | + context: . |
| 104 | + file: ./Dockerfile # Path to your Dockerfile |
| 105 | + push: false |
| 106 | + tags: ${{ steps.meta.outputs.tags }} |
| 107 | + outputs: type=oci,compression=gzip,dest=${{ steps.vars.outputs.image_path }}-${{ steps.vars.outputs.tag_hash }}.tar.gz |
| 108 | + cache-from: type=local,src=${{ steps.vars.outputs.cache_dir }} |
| 109 | + cache-to: type=local,mode=max,image-manifest=true,oci-mediatypes=true,dest=${{ steps.vars.outputs.cache_dir }} |
| 110 | + |
| 111 | + - name: Import image in containerd |
| 112 | + env: |
| 113 | + tag_hash: ${{ steps.vars.outputs.tag_hash }} |
| 114 | + image_path: ${{ steps.vars.outputs.image_path }} |
| 115 | + run: | |
| 116 | + echo "Importing $image_path-$tag_hash to Containerd" |
| 117 | + sudo ctr i import --no-unpack --all-platforms --digests $image_path-$tag_hash.tar.gz |
| 118 | +
|
| 119 | + - name: Push image with containerd |
| 120 | + env: |
| 121 | + tags: ${{ steps.meta.outputs.tags }} |
| 122 | + run: | |
| 123 | + for tag in $tags |
| 124 | + do |
| 125 | + echo "Pushing $tag to GHCR" |
| 126 | + sudo ctr i push --user "${{ github.repository_owner }}:${{ secrets.GHCR_PAT }}" $tag |
| 127 | + done |
| 128 | +
|
| 129 | + - name: Create and push soci index |
| 130 | + env: |
| 131 | + tags: ${{ steps.meta.outputs.tags }} |
| 132 | + run: | |
| 133 | + export SOCI_PATH=$HOME/.soci/soci |
| 134 | + for tag in $tags |
| 135 | + do |
| 136 | + echo "Creating soci index for $tag" |
| 137 | + sudo $SOCI_PATH create $tag |
| 138 | + echo "Pushing soci index for $tag" |
| 139 | + sudo $SOCI_PATH push --user ${{ github.repository_owner }}:${{ secrets.GHCR_PAT }} $tag |
| 140 | + done |
| 141 | +
|
| 142 | + - name: Prune older images |
| 143 | + env: |
| 144 | + tag_hash: ${{ steps.vars.outputs.tag_hash }} |
| 145 | + image_path: ${{ steps.vars.outputs.image_path }} |
| 146 | + run: | |
| 147 | + # Delete images older than a day from docker store |
| 148 | + docker image prune -a -f --filter "until=24h" |
| 149 | +
|
| 150 | + # Delete the on disk copy |
| 151 | + rm -rf "$image_path-$tag_hash.tar.gz" |
| 152 | +
|
| 153 | + # Delete the SHA image(s) from containerd store |
| 154 | + sudo ctr i rm $(sudo ctr i ls -q) |
0 commit comments