Skip to content

Commit 29950bb

Browse files
authored
Create docker.yml
1 parent 468d866 commit 29950bb

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed

.github/workflows/docker.yml

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Publish Docker image
11+
12+
on:
13+
workflow_dispatch: # allows manual triggering
14+
schedule:
15+
# Rebuild daily rather than on every push because it is expensive
16+
- cron: '12 4 * * *'
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
20+
cancel-in-progress: true
21+
22+
# Fine-grant permission
23+
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
24+
permissions:
25+
packages: write
26+
27+
jobs:
28+
push_to_registry:
29+
name: Push Docker image to Docker Hub
30+
31+
runs-on: ubuntu-latest
32+
env:
33+
COMMIT_SHA: ${{ github.sha }}
34+
strategy:
35+
matrix:
36+
config:
37+
- { tag: "light", dockerfile: ".devops/llama-cli.Dockerfile", platforms: "linux/amd64,linux/arm64" }
38+
- { tag: "server", dockerfile: ".devops/llama-server.Dockerfile", platforms: "linux/amd64,linux/arm64" }
39+
- { tag: "full", dockerfile: ".devops/full.Dockerfile", platforms: "linux/amd64,linux/arm64" }
40+
- { tag: "light-cuda", dockerfile: ".devops/llama-cli-cuda.Dockerfile", platforms: "linux/amd64" }
41+
- { tag: "server-cuda", dockerfile: ".devops/llama-server-cuda.Dockerfile", platforms: "linux/amd64" }
42+
- { tag: "full-cuda", dockerfile: ".devops/full-cuda.Dockerfile", platforms: "linux/amd64" }
43+
- { tag: "light-musa", dockerfile: ".devops/llama-cli-musa.Dockerfile", platforms: "linux/amd64" }
44+
- { tag: "server-musa", dockerfile: ".devops/llama-server-musa.Dockerfile", platforms: "linux/amd64" }
45+
- { tag: "full-musa", dockerfile: ".devops/full-musa.Dockerfile", platforms: "linux/amd64" }
46+
# Note: the rocm images are failing due to a compiler error and are disabled until this is fixed to allow the workflow to complete
47+
#- { tag: "light-rocm", dockerfile: ".devops/llama-cli-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
48+
#- { tag: "server-rocm", dockerfile: ".devops/llama-server-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
49+
#- { tag: "full-rocm", dockerfile: ".devops/full-rocm.Dockerfile", platforms: "linux/amd64,linux/arm64" }
50+
- { tag: "light-intel", dockerfile: ".devops/llama-cli-intel.Dockerfile", platforms: "linux/amd64" }
51+
- { tag: "server-intel", dockerfile: ".devops/llama-server-intel.Dockerfile", platforms: "linux/amd64" }
52+
steps:
53+
- name: Check out the repo
54+
uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0 # preserve git history, so we can determine the build number
57+
58+
- name: Set up QEMU
59+
uses: docker/setup-qemu-action@v2
60+
61+
- name: Set up Docker Buildx
62+
uses: docker/setup-buildx-action@v2
63+
64+
- name: Log in to Docker Hub
65+
uses: docker/login-action@v2
66+
with:
67+
registry: ghcr.io
68+
username: ${{ github.repository_owner }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Determine tag name
72+
id: tag
73+
shell: bash
74+
run: |
75+
BUILD_NUMBER="$(git rev-list --count HEAD)"
76+
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
77+
REPO_OWNER="${GITHUB_REPOSITORY_OWNER@L}" # to lower case
78+
REPO_NAME="${{ github.event.repository.name }}"
79+
80+
# determine tag name postfix (build number, commit hash)
81+
if [[ "${{ env.GITHUB_BRANCH_NAME }}" == "master" ]]; then
82+
TAG_POSTFIX="b${BUILD_NUMBER}"
83+
else
84+
SAFE_NAME=$(echo "${{ env.GITHUB_BRANCH_NAME }}" | tr '/' '-')
85+
TAG_POSTFIX="${SAFE_NAME}-${SHORT_HASH}"
86+
fi
87+
88+
# list all tags possible
89+
TAGS=""
90+
TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }},"
91+
TAGS="${TAGS}ghcr.io/${REPO_OWNER}/${REPO_NAME}:${{ matrix.config.tag }}-${TAG_POSTFIX}"
92+
93+
echo "output_tags=$TAGS" >> $GITHUB_OUTPUT
94+
echo "output_tags=$TAGS" # print out for debugging
95+
env:
96+
GITHUB_BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
97+
GITHUB_REPOSITORY_OWNER: '${{ github.repository_owner }}'
98+
99+
# https://github.com/jlumbroso/free-disk-space/tree/54081f138730dfa15788a46383842cd2f914a1be#example
100+
- name: Free Disk Space (Ubuntu)
101+
uses: jlumbroso/free-disk-space@main
102+
with:
103+
# this might remove tools that are actually needed,
104+
# if set to "true" but frees about 6 GB
105+
tool-cache: false
106+
107+
# all of these default to true, but feel free to set to
108+
# "false" if necessary for your workflow
109+
android: true
110+
dotnet: true
111+
haskell: true
112+
large-packages: true
113+
docker-images: true
114+
swap-storage: true
115+
116+
- name: Build and push Docker image (tagged + versioned)
117+
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }}
118+
uses: docker/build-push-action@v6
119+
with:
120+
context: .
121+
push: true
122+
platforms: ${{ matrix.config.platforms }}
123+
# tag list is generated from step above
124+
tags: ${{ steps.tag.outputs.output_tags }}
125+
file: ${{ matrix.config.dockerfile }}

0 commit comments

Comments
 (0)