Skip to content

Commit abeb7fa

Browse files
committed
Add Docker image build to CD pipeline with ghcr.io and Docker Hub support
1 parent 077f887 commit abeb7fa

3 files changed

Lines changed: 82 additions & 19 deletions

File tree

.github/workflows/python-publish.yml

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@ name: CD
1111
on:
1212
release:
1313
types: [published]
14-
14+
1515
workflow_dispatch:
1616

1717
permissions:
1818
contents: read
19+
packages: write
1920

2021
jobs:
2122
deploy:
22-
23+
name: Publish to PyPI
2324
runs-on: ubuntu-latest
2425

2526
steps:
26-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v4
2728
- name: Set up Python
28-
uses: actions/setup-python@v3
29+
uses: actions/setup-python@v5
2930
with:
3031
python-version: '3.x'
3132
- name: Install dependencies
@@ -39,3 +40,71 @@ jobs:
3940
with:
4041
user: __token__
4142
password: ${{ secrets.PYPI_API_TOKEN }}
43+
44+
docker:
45+
name: Build & Push Docker Image
46+
runs-on: ubuntu-latest
47+
48+
steps:
49+
- name: Checkout code
50+
uses: actions/checkout@v4
51+
52+
- name: Log in to GitHub Container Registry
53+
uses: docker/login-action@v3
54+
with:
55+
registry: ghcr.io
56+
username: ${{ github.actor }}
57+
password: ${{ github.token }}
58+
59+
- name: Extract metadata for Docker
60+
id: meta
61+
uses: docker/metadata-action@v5
62+
with:
63+
images: ghcr.io/${{ github.repository }}
64+
tags: |
65+
type=semver,pattern={{version}}
66+
type=raw,value=latest
67+
68+
- name: Build and push Docker image
69+
uses: docker/build-push-action@v6
70+
with:
71+
context: .
72+
file: docker/Dockerfile
73+
push: true
74+
tags: ${{ steps.meta.outputs.tags }}
75+
labels: ${{ steps.meta.outputs.labels }}
76+
77+
# TODO: To enable Docker Hub publishing, add DOCKERHUB_USERNAME and DOCKERHUB_TOKEN
78+
# as repository secrets.
79+
docker-hub:
80+
name: Push to Docker Hub
81+
runs-on: ubuntu-latest
82+
if: ${{ secrets.DOCKERHUB_USERNAME != '' }}
83+
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Log in to Docker Hub
89+
uses: docker/login-action@v3
90+
with:
91+
username: ${{ secrets.DOCKERHUB_USERNAME }}
92+
password: ${{ secrets.DOCKERHUB_TOKEN }}
93+
94+
- name: Extract metadata for Docker
95+
id: meta
96+
uses: docker/metadata-action@v5
97+
with:
98+
images: ${{ secrets.DOCKERHUB_USERNAME }}/ftio
99+
tags: |
100+
type=semver,pattern={{version}}
101+
type=raw,value=latest
102+
103+
- name: Build and push Docker image
104+
uses: docker/build-push-action@v6
105+
with:
106+
context: .
107+
file: docker/Dockerfile
108+
push: true
109+
tags: ${{ steps.meta.outputs.tags }}
110+
labels: ${{ steps.meta.outputs.labels }}

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ clean: clean_project
7777

7878

7979
docker:
80-
cd docker && docker build -t freq_io:1.0 .
80+
docker build -f docker/Dockerfile -t freq_io:1.0 .
8181

8282

8383
docker_run:
84-
cd docker && docker run -v "$$PWD/examples/tmio/JSONL/8.jsonl:/freq_io/8.jsonl" -t freq_io:1.0 ftio 8.jsonl -e no
84+
docker run -v "$$PWD/examples/tmio/JSONL/8.jsonl:/freq_io/8.jsonl" -t freq_io:1.0 8.jsonl -e no
8585

8686

8787
docker_interactive:
88-
cd docker && docker run -ti freq_io:1.0
88+
docker run -ti --entrypoint /bin/bash freq_io:1.0
8989

9090

9191

docker/Dockerfile

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1-
FROM python:latest
1+
FROM python:3.11-slim
22

3-
COPY ../ftio /freq_io/ftio
4-
# COPY ioparse /freq_io/ioparse
5-
# COPY install /freq_io/install
6-
# COPY prediction /freq_io/prediction
7-
# COPY predictor.py /freq_io/
8-
# COPY ftio.py /freq_io/
3+
COPY pyproject.toml README.md LICENSE /freq_io/
4+
COPY ftio /freq_io/ftio
95

106
WORKDIR /freq_io
117

12-
# RUN python3 -m venv ./venv
13-
RUN ls
14-
RUN python3 -m pip install .
15-
16-
CMD ["ftio.py", "-e", "no"]
8+
RUN python3 -m pip install --no-cache-dir .
9+
10+
ENTRYPOINT ["ftio"]

0 commit comments

Comments
 (0)