release.yaml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. name: release
  2. on:
  3. push:
  4. tags:
  5. - 'v*'
  6. jobs:
  7. # Full build of the Mac assets
  8. build-darwin:
  9. runs-on: macos-12
  10. environment: release
  11. steps:
  12. - uses: actions/checkout@v4
  13. - name: Set Version
  14. shell: bash
  15. run: |
  16. echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  17. echo "RELEASE_VERSION=$(echo ${GITHUB_REF_NAME} | cut -f1 -d-)" >> $GITHUB_ENV
  18. - name: key
  19. env:
  20. MACOS_SIGNING_KEY: ${{ secrets.MACOS_SIGNING_KEY }}
  21. MACOS_SIGNING_KEY_PASSWORD: ${{ secrets.MACOS_SIGNING_KEY_PASSWORD }}
  22. run: |
  23. echo $MACOS_SIGNING_KEY | base64 --decode > certificate.p12
  24. security create-keychain -p password build.keychain
  25. security default-keychain -s build.keychain
  26. security unlock-keychain -p password build.keychain
  27. security import certificate.p12 -k build.keychain -P $MACOS_SIGNING_KEY_PASSWORD -T /usr/bin/codesign
  28. security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k password build.keychain
  29. security set-keychain-settings -lut 3600 build.keychain
  30. - uses: actions/setup-go@v5
  31. with:
  32. go-version-file: go.mod
  33. cache: true
  34. - name: Build Darwin
  35. env:
  36. APPLE_IDENTITY: ${{ secrets.APPLE_IDENTITY }}
  37. APPLE_PASSWORD: ${{ secrets.APPLE_PASSWORD }}
  38. APPLE_TEAM_ID: ${{ vars.APPLE_TEAM_ID }}
  39. APPLE_ID: ${{ vars.APPLE_ID }}
  40. SDKROOT: /Applications/Xcode_13.4.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
  41. DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
  42. run: |
  43. ./scripts/build_darwin.sh
  44. - uses: actions/upload-artifact@v4
  45. with:
  46. name: dist-darwin
  47. path: |
  48. dist/*arwin*
  49. !dist/*-cov
  50. # Windows builds take a long time to both install the dependencies and build, so parallelize
  51. # CPU generation step
  52. generate-windows-cpu:
  53. environment: release
  54. runs-on: windows
  55. env:
  56. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  57. steps:
  58. - uses: actions/checkout@v4
  59. - name: Set Version
  60. shell: bash
  61. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  62. - uses: 'google-github-actions/auth@v2'
  63. with:
  64. project_id: 'ollama'
  65. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  66. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  67. - name: install Windows SDK 8.1 to get signtool
  68. run: |
  69. $ErrorActionPreference = "Stop"
  70. write-host "downloading SDK"
  71. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  72. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  73. write-host "Win SDK 8.1 installed"
  74. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  75. - name: install signing plugin
  76. run: |
  77. $ErrorActionPreference = "Stop"
  78. write-host "downloading plugin"
  79. Invoke-WebRequest -Uri "https://github.com/GoogleCloudPlatform/kms-integrations/releases/download/cng-v1.0/kmscng-1.0-windows-amd64.zip" -OutFile "${env:RUNNER_TEMP}\plugin.zip"
  80. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  81. write-host "Installing plugin"
  82. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  83. write-host "plugin installed"
  84. - uses: actions/setup-go@v5
  85. with:
  86. go-version-file: go.mod
  87. cache: true
  88. - run: go get ./...
  89. - run: |
  90. $gopath=(get-command go).source | split-path -parent
  91. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  92. cd $env:GITHUB_WORKSPACE
  93. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  94. $env:PATH="$gopath;$env:PATH"
  95. go generate -x ./...
  96. name: go generate
  97. - uses: actions/upload-artifact@v4
  98. with:
  99. name: generate-windows-cpu
  100. path: |
  101. build/**/*
  102. build/**/*.a
  103. llm/build/**/*.a
  104. dist/windows-amd64/**
  105. # ROCm generation step
  106. generate-windows-rocm:
  107. environment: release
  108. runs-on: windows
  109. env:
  110. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  111. steps:
  112. - uses: actions/checkout@v4
  113. - name: Set Version
  114. shell: bash
  115. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  116. - uses: 'google-github-actions/auth@v2'
  117. with:
  118. project_id: 'ollama'
  119. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  120. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  121. - name: install Windows SDK 8.1 to get signtool
  122. run: |
  123. $ErrorActionPreference = "Stop"
  124. write-host "downloading SDK"
  125. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  126. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  127. write-host "Win SDK 8.1 installed"
  128. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  129. - name: install signing plugin
  130. run: |
  131. $ErrorActionPreference = "Stop"
  132. write-host "downloading plugin"
  133. Invoke-WebRequest -Uri "https://github.com/GoogleCloudPlatform/kms-integrations/releases/download/cng-v1.0/kmscng-1.0-windows-amd64.zip" -OutFile "${env:RUNNER_TEMP}\plugin.zip"
  134. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  135. write-host "Installing plugin"
  136. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  137. write-host "plugin installed"
  138. - uses: actions/setup-go@v5
  139. with:
  140. go-version-file: go.mod
  141. cache: true
  142. - name: 'Install ROCm'
  143. run: |
  144. $ErrorActionPreference = "Stop"
  145. write-host "downloading AMD HIP Installer"
  146. Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe"
  147. write-host "Installing AMD HIP"
  148. Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
  149. write-host "Completed AMD HIP"
  150. - name: 'Verify ROCm'
  151. run: |
  152. & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
  153. - run: go get ./...
  154. - run: |
  155. $gopath=(get-command go).source | split-path -parent
  156. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  157. cd $env:GITHUB_WORKSPACE
  158. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  159. $env:PATH="$gopath;$env:PATH"
  160. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  161. $env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
  162. go generate -x ./...
  163. name: go generate
  164. - name: 'gather rocm dependencies'
  165. run: |
  166. $HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
  167. md "dist\deps\bin\rocblas\library"
  168. cp "${HIP_PATH}\bin\hipblas.dll" "dist\deps\bin\"
  169. cp "${HIP_PATH}\bin\rocblas.dll" "dist\deps\bin\"
  170. cp "${HIP_PATH}\bin\rocblas\library\*" "dist\deps\bin\rocblas\library\"
  171. - uses: actions/upload-artifact@v4
  172. with:
  173. name: generate-windows-rocm
  174. path: |
  175. build/**/*
  176. dist/windows-amd64/**
  177. - uses: actions/upload-artifact@v4
  178. with:
  179. name: windows-rocm-deps
  180. path: dist/deps/*
  181. # CUDA generation step
  182. generate-windows-cuda:
  183. environment: release
  184. runs-on: windows
  185. strategy:
  186. matrix:
  187. cuda:
  188. - version: "11"
  189. url: 'https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe'
  190. - version: "12"
  191. url: 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe'
  192. env:
  193. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  194. steps:
  195. - uses: actions/checkout@v4
  196. - name: Set Version
  197. shell: bash
  198. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  199. - uses: 'google-github-actions/auth@v2'
  200. with:
  201. project_id: 'ollama'
  202. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  203. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  204. - name: install Windows SDK 8.1 to get signtool
  205. run: |
  206. $ErrorActionPreference = "Stop"
  207. write-host "downloading SDK"
  208. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  209. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  210. write-host "Win SDK 8.1 installed"
  211. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  212. - name: install signing plugin
  213. run: |
  214. $ErrorActionPreference = "Stop"
  215. write-host "downloading plugin"
  216. Invoke-WebRequest -Uri "https://github.com/GoogleCloudPlatform/kms-integrations/releases/download/cng-v1.0/kmscng-1.0-windows-amd64.zip" -OutFile "${env:RUNNER_TEMP}\plugin.zip"
  217. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  218. write-host "Installing plugin"
  219. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  220. write-host "plugin installed"
  221. - uses: actions/setup-go@v5
  222. with:
  223. go-version-file: go.mod
  224. cache: true
  225. - name: 'Install CUDA ${{ matrix.cuda.version }}'
  226. run: |
  227. $ErrorActionPreference = "Stop"
  228. write-host "downloading CUDA Installer"
  229. Invoke-WebRequest -Uri "${{ matrix.cuda.url }}" -OutFile "${env:RUNNER_TEMP}\cuda-install.exe"
  230. write-host "Installing CUDA"
  231. Start-Process "${env:RUNNER_TEMP}\cuda-install.exe" -ArgumentList '-s' -NoNewWindow -Wait
  232. write-host "Completed CUDA"
  233. $cudaPath=((resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0].path | split-path | split-path)
  234. $cudaVer=($cudaPath | split-path -leaf ) -replace 'v(\d+).(\d+)', '$1_$2'
  235. echo "$cudaPath\bin" >> $env:GITHUB_PATH
  236. echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV
  237. echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV
  238. echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV
  239. - name: 'Verify CUDA'
  240. run: nvcc -V
  241. - run: go get ./...
  242. - name: go generate
  243. run: |
  244. $gopath=(get-command go).source | split-path -parent
  245. $cudabin=(get-command nvcc).source | split-path
  246. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  247. cd $env:GITHUB_WORKSPACE
  248. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  249. $env:PATH="$gopath;$cudabin;$env:PATH"
  250. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  251. go generate -x ./...
  252. - name: 'gather cuda dependencies'
  253. run: |
  254. $NVIDIA_DIR=(resolve-path 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\*\bin\')[0]
  255. md "dist\deps"
  256. cp "${NVIDIA_DIR}\cudart64_*.dll" "dist\deps\"
  257. cp "${NVIDIA_DIR}\cublas64_*.dll" "dist\deps\"
  258. cp "${NVIDIA_DIR}\cublasLt64_*.dll" "dist\deps\"
  259. - uses: actions/upload-artifact@v4
  260. with:
  261. name: generate-windows-cuda-${{ matrix.cuda.version }}
  262. path: |
  263. build/**/*
  264. dist/windows-amd64/**
  265. - uses: actions/upload-artifact@v4
  266. with:
  267. name: windows-cuda-deps-${{ matrix.cuda.version }}
  268. path: dist/deps/*
  269. # Import the prior generation steps and build the final windows assets
  270. build-windows:
  271. environment: release
  272. runs-on: windows
  273. needs:
  274. - generate-windows-cuda
  275. - generate-windows-rocm
  276. - generate-windows-cpu
  277. env:
  278. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  279. steps:
  280. - uses: actions/checkout@v4
  281. with:
  282. submodules: recursive
  283. - name: Set Version
  284. shell: bash
  285. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  286. - uses: 'google-github-actions/auth@v2'
  287. with:
  288. project_id: 'ollama'
  289. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  290. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  291. - name: install Windows SDK 8.1 to get signtool
  292. run: |
  293. $ErrorActionPreference = "Stop"
  294. write-host "downloading SDK"
  295. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  296. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  297. write-host "Win SDK 8.1 installed"
  298. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  299. - name: install signing plugin
  300. run: |
  301. $ErrorActionPreference = "Stop"
  302. write-host "downloading plugin"
  303. Invoke-WebRequest -Uri "https://github.com/GoogleCloudPlatform/kms-integrations/releases/download/cng-v1.0/kmscng-1.0-windows-amd64.zip" -OutFile "${env:RUNNER_TEMP}\plugin.zip"
  304. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  305. write-host "Installing plugin"
  306. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  307. write-host "plugin installed"
  308. - uses: actions/setup-go@v5
  309. with:
  310. go-version-file: go.mod
  311. cache: true
  312. - run: go get
  313. - uses: actions/download-artifact@v4
  314. with:
  315. name: generate-windows-cpu
  316. - uses: actions/download-artifact@v4
  317. with:
  318. name: generate-windows-cuda-11
  319. - uses: actions/download-artifact@v4
  320. with:
  321. name: generate-windows-cuda-12
  322. - uses: actions/download-artifact@v4
  323. with:
  324. name: windows-cuda-deps-11
  325. - uses: actions/download-artifact@v4
  326. with:
  327. name: windows-cuda-deps-12
  328. - uses: actions/download-artifact@v4
  329. with:
  330. name: windows-rocm-deps
  331. - uses: actions/download-artifact@v4
  332. with:
  333. name: generate-windows-rocm
  334. - run: dir build
  335. - run: |
  336. $gopath=(get-command go).source | split-path -parent
  337. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  338. cd $env:GITHUB_WORKSPACE
  339. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  340. $env:PATH="$gopath;$env:PATH"
  341. $env:OLLAMA_SKIP_GENERATE="1"
  342. & .\scripts\build_windows.ps1
  343. - uses: actions/upload-artifact@v4
  344. with:
  345. name: dist-windows
  346. path: |
  347. dist/OllamaSetup.exe
  348. dist/ollama-windows-*.zip
  349. # Linux x86 assets built using the container based build
  350. build-linux-amd64:
  351. environment: release
  352. runs-on: linux
  353. env:
  354. PLATFORM: linux/amd64
  355. steps:
  356. - uses: actions/checkout@v4
  357. with:
  358. submodules: recursive
  359. - name: Set Version
  360. shell: bash
  361. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  362. - run: |
  363. ./scripts/build_linux.sh
  364. - uses: actions/upload-artifact@v4
  365. with:
  366. name: dist-linux-amd64
  367. path: |
  368. dist/*linux*
  369. !dist/*-cov
  370. # Linux ARM assets built using the container based build
  371. # (at present, docker isn't pre-installed on arm ubunutu images)
  372. build-linux-arm64:
  373. environment: release
  374. runs-on: linux-arm64
  375. env:
  376. PLATFORM: linux/arm64
  377. steps:
  378. - uses: actions/checkout@v4
  379. with:
  380. submodules: recursive
  381. - name: Set Version
  382. shell: bash
  383. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  384. - name: 'Install Docker'
  385. run: |
  386. # Add Docker's official GPG key:
  387. env
  388. uname -a
  389. sudo apt-get update
  390. sudo apt-get install -y ca-certificates curl
  391. sudo install -m 0755 -d /etc/apt/keyrings
  392. sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  393. sudo chmod a+r /etc/apt/keyrings/docker.asc
  394. # Add the repository to Apt sources:
  395. echo \
  396. "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  397. $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  398. sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  399. sudo apt-get update
  400. sudo apt-get install -y docker-ce docker-ce-cli containerd.io
  401. sudo usermod -aG docker $USER
  402. sudo apt-get install acl
  403. sudo setfacl --modify user:$USER:rw /var/run/docker.sock
  404. - run: |
  405. ./scripts/build_linux.sh
  406. - uses: actions/upload-artifact@v4
  407. with:
  408. name: dist-linux-arm64
  409. path: |
  410. dist/*linux*
  411. !dist/*-cov
  412. # Container image build
  413. build-container-image:
  414. environment: release
  415. strategy:
  416. matrix:
  417. runner:
  418. - linux
  419. - linux-arm64
  420. runs-on: ${{ matrix.runner }}
  421. env:
  422. FINAL_IMAGE_REPO: ollama/ollama
  423. steps:
  424. - uses: actions/checkout@v4
  425. with:
  426. submodules: recursive
  427. - name: 'Install Docker'
  428. if: ${{ startsWith(matrix.runner, 'linux-arm64') }}
  429. run: |
  430. sudo apt-get update
  431. sudo apt-get install -y ca-certificates curl
  432. sudo install -m 0755 -d /etc/apt/keyrings
  433. sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  434. sudo chmod a+r /etc/apt/keyrings/docker.asc
  435. echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  436. $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  437. sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  438. sudo apt-get update
  439. sudo apt-get install -y docker-ce docker-ce-cli containerd.io
  440. sudo usermod -aG docker $USER
  441. sudo apt-get install acl
  442. sudo setfacl --modify user:$USER:rw /var/run/docker.sock
  443. - name: Docker meta
  444. id: meta
  445. uses: docker/metadata-action@v5
  446. with:
  447. images: ${{ env.FINAL_IMAGE_REPO }}
  448. flavor: |
  449. latest=false
  450. tags: |
  451. type=ref,enable=true,priority=600,prefix=0.0.0-pr,suffix=,event=pr
  452. type=semver,pattern={{version}}
  453. - name: Set Version
  454. shell: bash
  455. run: |
  456. machine=$(uname -m)
  457. case ${machine} in
  458. x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;;
  459. aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;;
  460. esac >>$GITHUB_ENV
  461. echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" >>$GITHUB_ENV
  462. - name: Set up Docker Buildx
  463. uses: docker/setup-buildx-action@v3
  464. - name: Login to Docker Hub
  465. uses: docker/login-action@v3
  466. with:
  467. username: ${{ vars.DOCKER_USER }}
  468. password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
  469. - name: Build and push by digest
  470. id: build
  471. uses: docker/build-push-action@v6
  472. with:
  473. context: "."
  474. platforms: linux/${{ env.ARCH }}
  475. build-args: |
  476. GOFLAGS
  477. outputs: type=image,name=${{ env.FINAL_IMAGE_REPO }},push-by-digest=true,name-canonical=true,push=true
  478. - name: Export digest
  479. run: |
  480. mkdir -p /tmp/digests
  481. digest="${{ steps.build.outputs.digest }}"
  482. touch "/tmp/digests/${digest#sha256:}"
  483. - name: Upload digest
  484. uses: actions/upload-artifact@v4
  485. with:
  486. name: digests-${{ env.PLATFORM_PAIR }}
  487. path: /tmp/digests/*
  488. if-no-files-found: error
  489. retention-days: 1
  490. merge:
  491. environment: release
  492. runs-on: linux
  493. needs:
  494. - build-container-image
  495. env:
  496. FINAL_IMAGE_REPO: ollama/ollama
  497. steps:
  498. - uses: actions/checkout@v4
  499. with:
  500. submodules: recursive
  501. - name: Download digests
  502. uses: actions/download-artifact@v4
  503. with:
  504. path: /tmp/digests
  505. pattern: digests-*
  506. merge-multiple: true
  507. - name: Set up Docker Buildx
  508. uses: docker/setup-buildx-action@v3
  509. - name: Docker meta
  510. id: meta
  511. uses: docker/metadata-action@v5
  512. with:
  513. images: ${{ env.FINAL_IMAGE_REPO }}
  514. flavor: |
  515. latest=false
  516. tags: |
  517. type=ref,enable=true,priority=600,prefix=0.0.0-pr,suffix=,event=pr
  518. type=semver,pattern={{version}}
  519. - name: Set Version
  520. shell: bash
  521. run: |
  522. machine=$(uname -m)
  523. case ${machine} in
  524. x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;;
  525. aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;;
  526. esac >>$GITHUB_ENV
  527. echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" >>$GITHUB_ENV
  528. - name: Login to Docker Hub
  529. uses: docker/login-action@v3
  530. with:
  531. username: ${{ vars.DOCKER_USER }}
  532. password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
  533. - name: Create manifest list and push
  534. working-directory: /tmp/digests
  535. run: |
  536. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  537. $(printf '${{ env.FINAL_IMAGE_REPO }}@sha256:%s ' *)
  538. - name: Inspect image
  539. run: |
  540. docker buildx imagetools inspect ${{ env.FINAL_IMAGE_REPO }}:${{ steps.meta.outputs.version }}
  541. build-container-image-rocm:
  542. environment: release
  543. runs-on: linux
  544. env:
  545. FINAL_IMAGE_REPO: ollama/ollama
  546. ARCH: amd64
  547. PLATFORM_PAIR: linux-amd64
  548. steps:
  549. - uses: actions/checkout@v4
  550. with:
  551. submodules: recursive
  552. - name: Docker meta
  553. id: meta
  554. uses: docker/metadata-action@v5
  555. with:
  556. images: ${{ env.FINAL_IMAGE_REPO }}
  557. flavor: |
  558. latest=false
  559. tags: |
  560. type=ref,enable=true,priority=600,prefix=0.0.0-pr,suffix=,event=pr
  561. type=semver,pattern={{version}}
  562. - name: Set Version
  563. shell: bash
  564. run: |
  565. echo GOFLAGS="'-ldflags=-w -s \"-X=github.com/ollama/ollama/version.Version=${{ env.DOCKER_METADATA_OUTPUT_VERSION }}\" \"-X=github.com/ollama/ollama/server.mode=release\"'" >>$GITHUB_ENV
  566. - name: Set up Docker Buildx
  567. uses: docker/setup-buildx-action@v3
  568. - name: Login to Docker Hub
  569. uses: docker/login-action@v3
  570. with:
  571. username: ${{ vars.DOCKER_USER }}
  572. password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
  573. - name: Build and push by digest
  574. id: build
  575. uses: docker/build-push-action@v6
  576. with:
  577. context: "."
  578. target: runtime-rocm
  579. build-args: |
  580. GOFLAGS
  581. tags: ${{ env.FINAL_IMAGE_REPO }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION}}-rocm
  582. push: true
  583. # Aggregate all the assets and ship a release
  584. release:
  585. needs:
  586. - build-darwin
  587. - build-windows
  588. - build-linux-amd64
  589. - build-linux-arm64
  590. runs-on: linux
  591. environment: release
  592. permissions:
  593. contents: write
  594. env:
  595. GH_TOKEN: ${{ github.token }}
  596. steps:
  597. - uses: actions/checkout@v4
  598. - name: Set Version
  599. shell: bash
  600. run: |
  601. echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  602. echo "RELEASE_VERSION=$(echo ${GITHUB_REF_NAME} | cut -f1 -d-)" >> $GITHUB_ENV
  603. - name: Retrieve built artifact
  604. uses: actions/download-artifact@v4
  605. with:
  606. path: dist
  607. pattern: dist-*
  608. merge-multiple: true
  609. - run: |
  610. ls -lh dist/
  611. (cd dist; find . -type f | xargs sha256sum > ../sha256sum.txt)
  612. mv sha256sum.txt dist/
  613. mv dist/linux-???64 .
  614. mv dist/linux-amd64-rocm .
  615. cat dist/sha256sum.txt
  616. - name: Create or update Release
  617. run: |
  618. echo "Looking for existing release for ${{ env.RELEASE_VERSION }}"
  619. OLD_TAG=$(gh release ls --json name,tagName | jq -r ".[] | select(.name == \"${{ env.RELEASE_VERSION }}\") | .tagName")
  620. if [ -n "$OLD_TAG" ]; then
  621. echo "Updating release ${{ env.RELEASE_VERSION }} to point to new tag ${GITHUB_REF_NAME}"
  622. gh release edit ${OLD_TAG} --tag ${GITHUB_REF_NAME}
  623. else
  624. echo "Creating new release ${{ env.RELEASE_VERSION }} pointing to tag ${GITHUB_REF_NAME}"
  625. gh release create ${GITHUB_REF_NAME} \
  626. --title ${{ env.RELEASE_VERSION }} \
  627. --draft \
  628. --generate-notes \
  629. --prerelease
  630. fi
  631. echo "Uploading artifacts for tag ${GITHUB_REF_NAME}"
  632. gh release upload ${GITHUB_REF_NAME} dist/* --clobber