release.yaml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. dist/windows-amd64/**
  104. # ROCm generation step
  105. generate-windows-rocm:
  106. environment: release
  107. runs-on: windows
  108. env:
  109. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  110. steps:
  111. - uses: actions/checkout@v4
  112. - name: Set Version
  113. shell: bash
  114. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  115. - uses: 'google-github-actions/auth@v2'
  116. with:
  117. project_id: 'ollama'
  118. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  119. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  120. - name: install Windows SDK 8.1 to get signtool
  121. run: |
  122. $ErrorActionPreference = "Stop"
  123. write-host "downloading SDK"
  124. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  125. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  126. write-host "Win SDK 8.1 installed"
  127. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  128. - name: install signing plugin
  129. run: |
  130. $ErrorActionPreference = "Stop"
  131. write-host "downloading plugin"
  132. 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"
  133. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  134. write-host "Installing plugin"
  135. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  136. write-host "plugin installed"
  137. - uses: actions/setup-go@v5
  138. with:
  139. go-version-file: go.mod
  140. cache: true
  141. - name: 'Install ROCm'
  142. run: |
  143. $ErrorActionPreference = "Stop"
  144. write-host "downloading AMD HIP Installer"
  145. 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"
  146. write-host "Installing AMD HIP"
  147. Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
  148. write-host "Completed AMD HIP"
  149. - name: 'Verify ROCm'
  150. run: |
  151. & 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
  152. - run: go get ./...
  153. - run: |
  154. $gopath=(get-command go).source | split-path -parent
  155. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  156. cd $env:GITHUB_WORKSPACE
  157. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  158. $env:PATH="$gopath;$env:PATH"
  159. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  160. $env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
  161. go generate -x ./...
  162. name: go generate
  163. - name: 'gather rocm dependencies'
  164. run: |
  165. $HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
  166. md "dist\deps\bin\rocblas\library"
  167. cp "${HIP_PATH}\bin\hipblas.dll" "dist\deps\bin\"
  168. cp "${HIP_PATH}\bin\rocblas.dll" "dist\deps\bin\"
  169. cp "${HIP_PATH}\bin\rocblas\library\*" "dist\deps\bin\rocblas\library\"
  170. - uses: actions/upload-artifact@v4
  171. with:
  172. name: generate-windows-rocm
  173. path: |
  174. build/**/*
  175. dist/windows-amd64/**
  176. - uses: actions/upload-artifact@v4
  177. with:
  178. name: windows-rocm-deps
  179. path: dist/deps/*
  180. # CUDA generation step
  181. generate-windows-cuda:
  182. environment: release
  183. runs-on: windows
  184. strategy:
  185. matrix:
  186. cuda:
  187. - version: "11"
  188. url: 'https://developer.download.nvidia.com/compute/cuda/11.3.1/local_installers/cuda_11.3.1_465.89_win10.exe'
  189. - version: "12"
  190. url: 'https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda_12.4.0_551.61_windows.exe'
  191. env:
  192. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  193. steps:
  194. - uses: actions/checkout@v4
  195. - name: Set Version
  196. shell: bash
  197. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  198. - uses: 'google-github-actions/auth@v2'
  199. with:
  200. project_id: 'ollama'
  201. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  202. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  203. - name: install Windows SDK 8.1 to get signtool
  204. run: |
  205. $ErrorActionPreference = "Stop"
  206. write-host "downloading SDK"
  207. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  208. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  209. write-host "Win SDK 8.1 installed"
  210. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  211. - name: install signing plugin
  212. run: |
  213. $ErrorActionPreference = "Stop"
  214. write-host "downloading plugin"
  215. 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"
  216. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  217. write-host "Installing plugin"
  218. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  219. write-host "plugin installed"
  220. - uses: actions/setup-go@v5
  221. with:
  222. go-version-file: go.mod
  223. cache: true
  224. - name: 'Install CUDA ${{ matrix.cuda.version }}'
  225. run: |
  226. $ErrorActionPreference = "Stop"
  227. write-host "downloading CUDA Installer"
  228. Invoke-WebRequest -Uri "${{ matrix.cuda.url }}" -OutFile "${env:RUNNER_TEMP}\cuda-install.exe"
  229. write-host "Installing CUDA"
  230. Start-Process "${env:RUNNER_TEMP}\cuda-install.exe" -ArgumentList '-s' -NoNewWindow -Wait
  231. write-host "Completed CUDA"
  232. $cudaPath=((resolve-path "c:\Program Files\NVIDIA*\CUDA\v*\bin\nvcc.exe")[0].path | split-path | split-path)
  233. $cudaVer=($cudaPath | split-path -leaf ) -replace 'v(\d+).(\d+)', '$1_$2'
  234. echo "$cudaPath\bin" >> $env:GITHUB_PATH
  235. echo "CUDA_PATH=$cudaPath" >> $env:GITHUB_ENV
  236. echo "CUDA_PATH_V${cudaVer}=$cudaPath" >> $env:GITHUB_ENV
  237. echo "CUDA_PATH_VX_Y=CUDA_PATH_V${cudaVer}" >> $env:GITHUB_ENV
  238. - name: 'Verify CUDA'
  239. run: nvcc -V
  240. - run: go get ./...
  241. - name: go generate
  242. run: |
  243. $gopath=(get-command go).source | split-path -parent
  244. $cudabin=(get-command nvcc).source | split-path
  245. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  246. cd $env:GITHUB_WORKSPACE
  247. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  248. $env:PATH="$gopath;$cudabin;$env:PATH"
  249. $env:OLLAMA_SKIP_CPU_GENERATE="1"
  250. go generate -x ./...
  251. - name: 'gather cuda dependencies'
  252. run: |
  253. $NVIDIA_DIR=(resolve-path 'C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\*\bin\')[0]
  254. md "dist\deps"
  255. cp "${NVIDIA_DIR}\cudart64_*.dll" "dist\deps\"
  256. cp "${NVIDIA_DIR}\cublas64_*.dll" "dist\deps\"
  257. cp "${NVIDIA_DIR}\cublasLt64_*.dll" "dist\deps\"
  258. - uses: actions/upload-artifact@v4
  259. with:
  260. name: generate-windows-cuda-${{ matrix.cuda.version }}
  261. path: |
  262. build/**/*
  263. dist/windows-amd64/**
  264. - uses: actions/upload-artifact@v4
  265. with:
  266. name: windows-cuda-deps-${{ matrix.cuda.version }}
  267. path: dist/deps/*
  268. # Import the prior generation steps and build the final windows assets
  269. build-windows:
  270. environment: release
  271. runs-on: windows
  272. needs:
  273. - generate-windows-cuda
  274. - generate-windows-rocm
  275. - generate-windows-cpu
  276. env:
  277. KEY_CONTAINER: ${{ vars.KEY_CONTAINER }}
  278. steps:
  279. - uses: actions/checkout@v4
  280. with:
  281. submodules: recursive
  282. - name: Set Version
  283. shell: bash
  284. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  285. - uses: 'google-github-actions/auth@v2'
  286. with:
  287. project_id: 'ollama'
  288. credentials_json: '${{ secrets.GOOGLE_SIGNING_CREDENTIALS }}'
  289. - run: echo "${{ vars.OLLAMA_CERT }}" > ollama_inc.crt
  290. - name: install Windows SDK 8.1 to get signtool
  291. run: |
  292. $ErrorActionPreference = "Stop"
  293. write-host "downloading SDK"
  294. Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/p/?LinkId=323507" -OutFile "${env:RUNNER_TEMP}\sdksetup.exe"
  295. Start-Process "${env:RUNNER_TEMP}\sdksetup.exe" -ArgumentList @("/q") -NoNewWindow -Wait
  296. write-host "Win SDK 8.1 installed"
  297. gci -path 'C:\Program Files (x86)\Windows Kits\' -r -fi 'signtool.exe'
  298. - name: install signing plugin
  299. run: |
  300. $ErrorActionPreference = "Stop"
  301. write-host "downloading plugin"
  302. 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"
  303. Expand-Archive -Path "${env:RUNNER_TEMP}\plugin.zip" -DestinationPath ${env:RUNNER_TEMP}\plugin\
  304. write-host "Installing plugin"
  305. & "${env:RUNNER_TEMP}\plugin\*\kmscng.msi" /quiet
  306. write-host "plugin installed"
  307. - uses: actions/setup-go@v5
  308. with:
  309. go-version-file: go.mod
  310. cache: true
  311. - run: go get
  312. - uses: actions/download-artifact@v4
  313. with:
  314. name: generate-windows-cpu
  315. - uses: actions/download-artifact@v4
  316. with:
  317. name: generate-windows-cuda-11
  318. - uses: actions/download-artifact@v4
  319. with:
  320. name: generate-windows-cuda-12
  321. - uses: actions/download-artifact@v4
  322. with:
  323. name: windows-cuda-deps-11
  324. - uses: actions/download-artifact@v4
  325. with:
  326. name: windows-cuda-deps-12
  327. - uses: actions/download-artifact@v4
  328. with:
  329. name: windows-rocm-deps
  330. - uses: actions/download-artifact@v4
  331. with:
  332. name: generate-windows-rocm
  333. - run: dir build
  334. - run: |
  335. $gopath=(get-command go).source | split-path -parent
  336. & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\Launch-VsDevShell.ps1"
  337. cd $env:GITHUB_WORKSPACE
  338. $env:CMAKE_SYSTEM_VERSION="10.0.22621.0"
  339. $env:PATH="$gopath;$env:PATH"
  340. $env:OLLAMA_SKIP_GENERATE="1"
  341. & .\scripts\build_windows.ps1
  342. - uses: actions/upload-artifact@v4
  343. with:
  344. name: dist-windows
  345. path: |
  346. dist/OllamaSetup.exe
  347. dist/ollama-windows-*.zip
  348. # Linux x86 assets built using the container based build
  349. build-linux-amd64:
  350. environment: release
  351. runs-on: linux
  352. env:
  353. BUILD_ARCH: amd64
  354. steps:
  355. - uses: actions/checkout@v4
  356. with:
  357. submodules: recursive
  358. - name: Set Version
  359. shell: bash
  360. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  361. - run: |
  362. ./scripts/build_linux.sh
  363. - uses: actions/upload-artifact@v4
  364. with:
  365. name: dist-linux-amd64
  366. path: |
  367. dist/*linux*
  368. !dist/*-cov
  369. # Linux ARM assets built using the container based build
  370. # (at present, docker isn't pre-installed on arm ubunutu images)
  371. build-linux-arm64:
  372. environment: release
  373. runs-on: linux-arm64
  374. env:
  375. BUILD_ARCH: arm64
  376. steps:
  377. - uses: actions/checkout@v4
  378. with:
  379. submodules: recursive
  380. - name: Set Version
  381. shell: bash
  382. run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  383. - name: 'Install Docker'
  384. run: |
  385. # Add Docker's official GPG key:
  386. env
  387. uname -a
  388. sudo apt-get update
  389. sudo apt-get install -y ca-certificates curl
  390. sudo install -m 0755 -d /etc/apt/keyrings
  391. sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  392. sudo chmod a+r /etc/apt/keyrings/docker.asc
  393. # Add the repository to Apt sources:
  394. echo \
  395. "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  396. $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  397. sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  398. sudo apt-get update
  399. sudo apt-get install -y docker-ce docker-ce-cli containerd.io
  400. sudo usermod -aG docker $USER
  401. sudo apt-get install acl
  402. sudo setfacl --modify user:$USER:rw /var/run/docker.sock
  403. - run: |
  404. ./scripts/build_linux.sh
  405. - uses: actions/upload-artifact@v4
  406. with:
  407. name: dist-linux-arm64
  408. path: |
  409. dist/*linux*
  410. !dist/*-cov
  411. # Container image build
  412. build-linux:
  413. environment: release
  414. strategy:
  415. matrix:
  416. runner:
  417. - linux
  418. - linux-arm64
  419. runs-on: ${{ matrix.runner }}
  420. env:
  421. FINAL_IMAGE_REPO: ollama/ollama
  422. steps:
  423. - uses: actions/checkout@v4
  424. with:
  425. submodules: recursive
  426. - name: 'Install Docker'
  427. if: ${{ startsWith(matrix.runner, 'linux-arm64') }}
  428. run: |
  429. sudo apt-get update
  430. sudo apt-get install -y ca-certificates curl
  431. sudo install -m 0755 -d /etc/apt/keyrings
  432. sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
  433. sudo chmod a+r /etc/apt/keyrings/docker.asc
  434. echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  435. $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  436. sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  437. sudo apt-get update
  438. sudo apt-get install -y docker-ce docker-ce-cli containerd.io
  439. sudo usermod -aG docker $USER
  440. sudo apt-get install acl
  441. sudo setfacl --modify user:$USER:rw /var/run/docker.sock
  442. - name: Docker meta
  443. id: meta
  444. uses: docker/metadata-action@v5
  445. with:
  446. images: ${{ env.FINAL_IMAGE_REPO }}
  447. flavor: |
  448. latest=false
  449. tags: |
  450. type=ref,event=tag
  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-linux
  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,event=tag
  518. type=ref,enable=true,priority=600,prefix=0.0.0-pr,suffix=,event=pr
  519. type=semver,pattern={{version}}
  520. - name: Set Version
  521. shell: bash
  522. run: |
  523. machine=$(uname -m)
  524. case ${machine} in
  525. x86_64) echo ARCH=amd64; echo PLATFORM_PAIR=linux-amd64 ;;
  526. aarch64) echo ARCH=arm64; echo PLATFORM_PAIR=linux-arm64 ;;
  527. esac >>$GITHUB_ENV
  528. 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
  529. - name: Login to Docker Hub
  530. uses: docker/login-action@v3
  531. with:
  532. username: ${{ vars.DOCKER_USER }}
  533. password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
  534. - name: Create manifest list and push
  535. working-directory: /tmp/digests
  536. run: |
  537. docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
  538. $(printf '${{ env.FINAL_IMAGE_REPO }}@sha256:%s ' *)
  539. - name: Inspect image
  540. run: |
  541. docker buildx imagetools inspect ${{ env.FINAL_IMAGE_REPO }}:${{ steps.meta.outputs.version }}
  542. build-linux-rocm:
  543. environment: release
  544. runs-on: linux
  545. env:
  546. FINAL_IMAGE_REPO: ollama/ollama
  547. ARCH: amd64
  548. PLATFORM_PAIR: linux-amd64
  549. steps:
  550. - uses: actions/checkout@v4
  551. with:
  552. submodules: recursive
  553. - name: Docker meta
  554. id: meta
  555. uses: docker/metadata-action@v5
  556. with:
  557. images: ${{ env.FINAL_IMAGE_REPO }}
  558. flavor: |
  559. latest=false
  560. tags: |
  561. type=ref,event=tag
  562. type=ref,enable=true,priority=600,prefix=0.0.0-pr,suffix=,event=pr
  563. type=semver,pattern={{version}}
  564. - name: Set Version
  565. shell: bash
  566. run: |
  567. 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
  568. - name: Set up Docker Buildx
  569. uses: docker/setup-buildx-action@v3
  570. - name: Login to Docker Hub
  571. uses: docker/login-action@v3
  572. with:
  573. username: ${{ vars.DOCKER_USER }}
  574. password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
  575. - name: Build and push by digest
  576. id: build
  577. uses: docker/build-push-action@v6
  578. with:
  579. context: "."
  580. target: runtime-rocm
  581. build-args: |
  582. GOFLAGS
  583. tags: ${{ env.FINAL_IMAGE_REPO }}:${{ env.DOCKER_METADATA_OUTPUT_VERSION}}-rocm,${{ env.FINAL_IMAGE_REPO }}:rocm
  584. push: true
  585. # Aggregate all the assets and ship a release
  586. release:
  587. needs:
  588. - build-darwin
  589. - build-windows
  590. - build-linux-amd64
  591. - build-linux-arm64
  592. runs-on: linux
  593. environment: release
  594. permissions:
  595. contents: write
  596. env:
  597. GH_TOKEN: ${{ github.token }}
  598. steps:
  599. - uses: actions/checkout@v4
  600. - name: Set Version
  601. shell: bash
  602. run: |
  603. echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
  604. echo "RELEASE_VERSION=$(echo ${GITHUB_REF_NAME} | cut -f1 -d-)" >> $GITHUB_ENV
  605. - name: Retrieve built artifact
  606. uses: actions/download-artifact@v4
  607. with:
  608. path: dist
  609. pattern: dist-*
  610. merge-multiple: true
  611. - run: |
  612. ls -lh dist/
  613. (cd dist; find . -type f | xargs sha256sum > ../sha256sum.txt)
  614. mv sha256sum.txt dist/
  615. mv dist/linux-???64 .
  616. mv dist/linux-amd64-rocm .
  617. cat dist/sha256sum.txt
  618. - name: Create or update Release
  619. run: |
  620. echo "Looking for existing release for ${{ env.RELEASE_VERSION }}"
  621. OLD_TAG=$(gh release ls --json name,tagName | jq -r ".[] | select(.name == \"${{ env.RELEASE_VERSION }}\") | .tagName")
  622. if [ -n "$OLD_TAG" ]; then
  623. echo "Updating release ${{ env.RELEASE_VERSION }} to point to new tag ${GITHUB_REF_NAME}"
  624. gh release edit ${OLD_TAG} --tag ${GITHUB_REF_NAME}
  625. else
  626. echo "Creating new release ${{ env.RELEASE_VERSION }} pointing to tag ${GITHUB_REF_NAME}"
  627. gh release create ${GITHUB_REF_NAME} \
  628. --title ${{ env.RELEASE_VERSION }} \
  629. --draft \
  630. --generate-notes \
  631. --prerelease
  632. fi
  633. echo "Uploading artifacts for tag ${GITHUB_REF_NAME}"
  634. gh release upload ${GITHUB_REF_NAME} dist/* --clobber