-
Notifications
You must be signed in to change notification settings - Fork 295
96 lines (84 loc) · 3.29 KB
/
docker.yml
File metadata and controls
96 lines (84 loc) · 3.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Docker Build and Push
on:
workflow_dispatch:
inputs:
update_latest:
description: '是否更新 latest 标签'
required: true
type: boolean
default: false
upload_artifacts:
description: '是否上传构建产物'
required: true
type: boolean
default: true
# push:
# tags:
# - 'v*'
env:
IMAGE_NAME: ${{ github.repository_owner }}/cursor-api
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4.2.2
- name: Get version from Cargo.toml
if: github.event_name == 'workflow_dispatch'
id: cargo_version
run: |
VERSION=$(grep '^version = ' Cargo.toml | cut -d '"' -f2)
echo "version=v${VERSION}" >> $GITHUB_OUTPUT
- name: Log in to Docker Hub
uses: docker/login-action@v3.4.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5.7.0
with:
images: ${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'workflow_dispatch' && inputs.update_latest }}
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
type=raw,value=${{ steps.cargo_version.outputs.version }},enable=${{ github.event_name == 'workflow_dispatch' }}
type=raw,value=${{ github.ref_name }},enable=${{ github.event_name == 'push' }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.10.0
with:
driver-opts: |
image=moby/buildkit:latest
network=host
- name: Build and push Docker image
uses: docker/build-push-action@v6.15.0
env:
DOCKER_BUILD_RECORD_UPLOAD: false
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
outputs: type=local,dest=./dist,enable=${{ (github.event_name == 'workflow_dispatch' && inputs.upload_artifacts) || github.event_name == 'push'}}
- name: Prepare artifacts
if: github.event_name == 'workflow_dispatch' && inputs.upload_artifacts
run: |
mkdir -p artifacts
cp dist/linux_amd64/app/cursor-api artifacts/cursor-api-x86_64-${{ steps.cargo_version.outputs.version }}
cp dist/linux_arm64/app/cursor-api artifacts/cursor-api-aarch64-${{ steps.cargo_version.outputs.version }}
- name: Prepare artifacts
if: github.event_name == 'push'
run: |
mkdir -p artifacts
cp dist/linux_amd64/app/cursor-api artifacts/cursor-api-x86_64-${{ github.ref_name }}
cp dist/linux_arm64/app/cursor-api artifacts/cursor-api-aarch64-${{ github.ref_name }}
- name: Upload artifacts
if: (github.event_name == 'workflow_dispatch' && inputs.upload_artifacts) || github.event_name == 'push'
uses: actions/upload-artifact@v4.6.0
with:
name: cursor-api-binaries
path: artifacts/
retention-days: 7