Skip to content

Commit bb9617e

Browse files
authored
Update docker-build-push.yml
1 parent 0ae026d commit bb9617e

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

.github/workflows/docker-build-push.yml

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ name: Build and Push Docker Image
33
on:
44
push:
55
branches:
6-
- main # 在推送到 main 分支时触发
6+
- main
77
pull_request:
88
branches:
9-
- main # 在对 main 分支的 PR 时触发
9+
- main
1010

1111
jobs:
1212
build-and-push:
@@ -25,13 +25,42 @@ jobs:
2525
username: ${{ secrets.DOCKER_USERNAME }}
2626
password: ${{ secrets.DOCKER_PASSWORD }}
2727

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
3564
3665
- name: Build and push Docker image
3766
uses: docker/build-push-action@v2

0 commit comments

Comments
 (0)