Skip to content

Commit fedc64e

Browse files
committed
Update tag format: add secure- prefix and timestamp tags
1 parent ea8afa5 commit fedc64e

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

.github/workflows/docker.yml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ on:
88
branches:
99
- main
1010
workflow_dispatch:
11+
inputs:
12+
platform:
13+
description: 'Platform to build'
14+
required: false
15+
default: 'linux/amd64,linux/arm64'
16+
type: choice
17+
options:
18+
- linux/amd64,linux/arm64
19+
- linux/amd64
1120

1221
env:
1322
# 使用 docker.io 作为 Docker Hub(如果为空)
@@ -46,14 +55,21 @@ jobs:
4655
username: ${{ github.actor }}
4756
password: ${{ secrets.GITHUB_TOKEN }}
4857

58+
- name: Generate timestamp
59+
id: timestamp
60+
run: echo "timestamp=$(date -u +'%Y%m%d-%H%M%S')" >> $GITHUB_OUTPUT
61+
4962
- name: Extract metadata
5063
id: meta
5164
uses: docker/metadata-action@v5
5265
with:
5366
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
5467
tags: |
5568
type=raw,value=latest,priority=500
56-
type=raw,value=${{ github.run_number }},priority=400
69+
type=raw,value=${{ steps.timestamp.outputs.timestamp }},priority=400
70+
type=raw,value=secure-${{ steps.timestamp.outputs.timestamp }},priority=300
71+
type=raw,value=secure-latest,priority=200
72+
type=raw,value=main-${{ github.sha }},priority=100
5773
5874
- name: Build and push Docker image
5975
id: build-and-push
@@ -66,9 +82,9 @@ jobs:
6682
labels: ${{ steps.meta.outputs.labels }}
6783
secrets: |
6884
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
69-
platforms: linux/amd64, linux/arm64
70-
cache-from: type=gha
71-
cache-to: type=gha,mode=max
85+
platforms: ${{ github.event.inputs.platform || 'linux/amd64,linux/arm64' }}
86+
cache-from: type=gha,scope=build
87+
cache-to: type=gha,mode=max,scope=build
7288

7389
- name: Attest Build Provenance
7490
uses: actions/attest-build-provenance@v3

Dockerfile

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
1+
# 构建阶段
2+
FROM python:3.11-slim as builder
3+
4+
# 安装构建依赖
5+
RUN apt-get update && \
6+
apt-get install -y --no-install-recommends \
7+
build-essential && \
8+
rm -rf /var/lib/apt/lists/*
9+
10+
# 安装 Python LSP Server
11+
RUN pip install --no-cache-dir --user 'python-lsp-server[all]'
12+
13+
# 运行阶段
114
FROM python:3.11-slim
215

316
# 创建用户和组
417
RUN groupadd -g 1000 python && \
518
useradd -m -u 1000 -g python python
619

7-
# 安装基础依赖
20+
# 安装运行时依赖
821
RUN apt-get update && \
922
apt-get install -y --no-install-recommends \
1023
ca-certificates \
1124
tini && \
1225
rm -rf /var/lib/apt/lists/*
1326

14-
# 安装 Python LSP Server
15-
RUN pip install --no-cache-dir 'python-lsp-server[all]'
27+
# 从构建阶段复制 Python
28+
COPY --from=builder --chown=python:python /root/.local /home/python/.local
1629

1730
# 设置环境变量
31+
ENV PATH=/home/python/.local/bin:$PATH
1832
ENV UID=1000 USER=python \
1933
GID=1000 GROUP=python \
2034
PYTHON_VERSION=3.11 \
@@ -24,6 +38,6 @@ ENV UID=1000 USER=python \
2438
USER python
2539

2640
# 设置工作目录
27-
WORKDIR /home/python
41+
WORKDIR /app
2842

2943
CMD ["pylsp"]

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ docker run --rm -it ghcr.io/reaslab/docker-lsp-python:latest
2727
| 镜像标签 | 描述 |
2828
|----------|------|
2929
| `latest` | 最新版本(Python 3.11 + 最新 LSP) |
30-
| `{run_number}` | 构建编号标签(如 `123`|
30+
| `{timestamp}` | 构建时间戳标签(如 `20241201-143022`|
3131

3232
### 环境变量
3333

@@ -36,7 +36,7 @@ docker run --rm -it ghcr.io/reaslab/docker-lsp-python:latest
3636
示例:
3737

3838
```sh
39-
docker run -e PYTHONPATH=/home/python ghcr.io/reaslab/docker-lsp-python:latest
39+
docker run -e PYTHONPATH=/app ghcr.io/reaslab/docker-lsp-python:latest
4040
```
4141

4242
### 使用 Docker Compose
@@ -51,8 +51,8 @@ services:
5151
volumes:
5252
- ~/.cache/python-lsp:/home/python/.cache
5353
- ~/.config/python-lsp:/home/python/.config
54-
- ./workspace:/home/python/workspace
55-
working_dir: /home/python/workspace
54+
- .:/app
55+
working_dir: /app
5656
command:
5757
- pylsp
5858
- --tcp
@@ -111,7 +111,7 @@ docker run -v /path/to/your/config.json:/home/python/.config/python-lsp/config.j
111111
- **推送构建**: 推送到 main 分支时自动构建
112112
- **手动构建**: 通过 workflow_dispatch 手动触发
113113
- **多架构支持**: 同时构建 amd64 和 arm64 架构
114-
- **标签策略**: `latest` 为最新版本,`{run_number}` 为构建编号
114+
- **标签策略**: `latest` 为最新版本,`{timestamp}` 为构建时间戳
115115

116116
## 开发
117117

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ services:
1212
volumes:
1313
- ~/.cache/python-lsp:/home/python/.cache
1414
- ~/.config/python-lsp:/home/python/.config
15-
- ./workspace:/workspace
16-
working_dir: /workspace
15+
- .:/app
16+
working_dir: /app
1717
command:
1818
- pylsp
1919
- --tcp

0 commit comments

Comments
 (0)