File tree Expand file tree Collapse file tree 1 file changed +38
-9
lines changed Expand file tree Collapse file tree 1 file changed +38
-9
lines changed Original file line number Diff line number Diff line change @@ -3,10 +3,10 @@ name: Build and Push Docker Image
3
3
on :
4
4
push :
5
5
branches :
6
- - main # 在推送到 main 分支时触发
6
+ - main
7
7
pull_request :
8
8
branches :
9
- - main # 在对 main 分支的 PR 时触发
9
+ - main
10
10
11
11
jobs :
12
12
build-and-push :
@@ -25,13 +25,42 @@ jobs:
25
25
username : ${{ secrets.DOCKER_USERNAME }}
26
26
password : ${{ secrets.DOCKER_PASSWORD }}
27
27
28
- - name : Cache Docker layers
29
- uses : actions/cache@v2
30
- with :
31
- path : /tmp/.buildx-cache
32
- key : ${{ runner.os }}-buildx-${{ github.sha }}
33
- restore-keys : |
34
- ${{ runner.os }}-buildx-
28
+ - name : Install yq
29
+ run : |
30
+ sudo apt-get update -y
31
+ sudo apt-get install -y python3-pip
32
+ pip3 install yq
33
+
34
+ - name : Read config.yaml and generate Dockerfile
35
+ id : generate_dockerfile
36
+ run : |
37
+ dependencies=$(yq e '.dependencies[]' config.yaml | tr '\n' ' ')
38
+ cat > Dockerfile <<EOL
39
+ FROM python:3.10-slim
40
+
41
+ WORKDIR /app
42
+
43
+ COPY requirements.txt .
44
+
45
+ RUN apt-get update && apt-get install -y \\
46
+ build-essential \\
47
+ libssl-dev \\
48
+ libffi-dev \\
49
+ python3-dev \\
50
+ libyaml-dev \\
51
+ && apt-get clean \\
52
+ && pip install --no-cache-dir --upgrade pip \\
53
+ && pip install --no-cache-dir cython \\
54
+ && pip install --no-cache-dir ${dependencies}
55
+
56
+ COPY . .
57
+
58
+ ENV PYTHONUNBUFFERED=1
59
+
60
+ EXPOSE 5000
61
+
62
+ CMD ["gunicorn", "-b", "0.0.0.0:5000", "app:app"]
63
+ EOL
35
64
36
65
- name : Build and push Docker image
37
66
uses : docker/build-push-action@v2
You can’t perform that action at this time.
0 commit comments