Skip to content
This repository was archived by the owner on Mar 13, 2024. It is now read-only.

Commit 888e60e

Browse files
committed
move wheel and sdist out of container
1 parent dd95a77 commit 888e60e

File tree

3 files changed

+83
-64
lines changed

3 files changed

+83
-64
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
build/
2-
dist/
32
.mypy_cache
43
.tox
54
.venv*

.github/workflows/code.yml

Lines changed: 80 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
schedule:
77
# Run every Monday at 8am to check latest versions of dependencies
88
- cron: "0 8 * * WED"
9+
env:
10+
# the target python version. Make sure the Dockerfile uses the same
11+
# version for its build and runtime targets.
12+
PYTHON: "3.10"
913

1014
jobs:
1115
lint:
@@ -20,7 +24,7 @@ jobs:
2024
- name: Setup python
2125
uses: actions/setup-python@v4
2226
with:
23-
python-version: "3.10"
27+
python-version: ${{env.PYTHON}}
2428

2529
- name: Lint
2630
run: |
@@ -53,7 +57,10 @@ jobs:
5357
python-version: ${{ matrix.python }}
5458

5559
- name: Install with latest dependencies
56-
run: pip install .[dev]
60+
run: |
61+
pip install .[dev]
62+
mkdir -p lockfiles
63+
pip freeze > lockfiles/requirements-dev-py${{ matrix.python }}.txt
5764
5865
- name: Run tests
5966
run: pytest tests
@@ -64,9 +71,62 @@ jobs:
6471
name: ${{ matrix.python }}/${{ matrix.os }}
6572
files: cov.xml
6673

74+
- name: Upload lock files
75+
uses: actions/upload-artifact@v3
76+
with:
77+
name: lockfiles
78+
path: lockfiles
79+
80+
dist:
81+
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
82+
runs-on: "ubuntu-latest"
83+
84+
steps:
85+
- name: Checkout Source
86+
uses: actions/checkout@v3
87+
with:
88+
fetch-depth: 0
89+
90+
- name: Setup python
91+
uses: actions/setup-python@v4
92+
with:
93+
python-version: ${{env.PYTHON}}
94+
95+
- name: Build Sdist and wheel
96+
run: |
97+
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
98+
pipx run --python $(which python${{env.PYTHON}}) build
99+
100+
# ${GITHUB_REPOSITORY##*/} is the repo name without org
101+
# Replace this with the cli command if different to the repo name
102+
- name: Test cli works in sdist installed in local python
103+
run: |
104+
touch requirements.txt
105+
pip install -r requirements.txt dist/*.gz ${GITHUB_REPOSITORY##*/} --version
106+
107+
# create a requirements.txt to be published as a github release asset
108+
- name: get a requirements.txt from the installed sdist
109+
run: |
110+
mkdir -p lockfiles
111+
pip freeze > lockfiles/requirements.txt
112+
113+
- name: Upload sdist and wheel as artifacts
114+
uses: actions/upload-artifact@v3
115+
with:
116+
name: dist
117+
path: dist
118+
119+
- name: Upload lock files
120+
uses: actions/upload-artifact@v3
121+
with:
122+
name: lockfiles
123+
path: lockfiles
124+
67125
container:
126+
needs: [dist]
68127
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
69128
runs-on: ubuntu-latest
129+
70130
permissions:
71131
contents: read
72132
packages: write
@@ -77,6 +137,12 @@ jobs:
77137
with:
78138
fetch-depth: 0
79139

140+
- uses: actions/download-artifact@v3
141+
142+
- name: PrepareReg Names
143+
run: |
144+
echo IMAGE_REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
145+
80146
- name: Log in to GitHub Docker Registry
81147
if: github.event_name != 'pull_request'
82148
uses: docker/login-action@v2
@@ -89,74 +155,43 @@ jobs:
89155
id: meta
90156
uses: docker/metadata-action@v4
91157
with:
92-
images: ghcr.io/${{ github.repository }}
158+
images: ${{env.IMAGE_REPOSITORY}}
93159
tags: |
94-
type=ref,event=branch
95160
type=ref,event=tag
161+
type=raw,value=latest
96162
97163
- name: Set up Docker Buildx
98164
id: buildx
99165
uses: docker/setup-buildx-action@v2
100166

101-
- name: Build developer image for testing
102-
uses: docker/build-push-action@v3
103-
with:
104-
tags: build:latest
105-
context: .
106-
target: build
107-
load: true
108-
109-
- name: Run tests in the container locked with requirements_dev.txt
110-
run: |
111-
docker run --name test build bash /project/.github/workflows/container_tests.sh
112-
docker cp test:/project/dist .
113-
docker cp test:/project/lockfiles .
114-
docker cp test:/project/cov.xml .
115-
116-
- name: Upload coverage to Codecov
117-
uses: codecov/codecov-action@v3
118-
with:
119-
name: 3.10-locked/ubuntu-latest
120-
files: cov.xml
121-
122167
- name: Build runtime image
123168
uses: docker/build-push-action@v3
124169
with:
125-
push: ${{ github.event_name != 'pull_request' }}
170+
push: true
171+
load: true
126172
tags: ${{ steps.meta.outputs.tags }}
127173
context: .
128-
labels: ${{ steps.meta.outputs.labels }}
129174

130175
- name: Test cli works in runtime image
131176
# check that the first tag can run with --version parameter
132-
run: docker run $(echo ${{ steps.meta.outputs.tags }} | head -1) --version
133-
134-
- name: Test cli works in sdist installed in local python
135-
# ${GITHUB_REPOSITORY##*/} is the repo name without org
136-
# Replace this with the cli command if different to the repo name
137-
run: pip install dist/*.gz && ${GITHUB_REPOSITORY##*/} --version
138-
139-
- name: Upload build files
140-
uses: actions/upload-artifact@v3
141-
with:
142-
name: dist
143-
path: dist
177+
run: docker run ${{env.IMAGE_REPOSITORY}}:latest --version
144178

145-
- name: Upload lock files
146-
uses: actions/upload-artifact@v3
147-
with:
148-
name: lockfiles
149-
path: lockfiles
179+
# TODO upload a tar of the image for later publishing
180+
# TODO OR do the publish here ??? if its quick enough - MUCH easier ?
150181

151182
release:
152183
# upload to PyPI and make a release on every tag
153184
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
154-
needs: container
185+
needs: [lint, dist]
155186
runs-on: ubuntu-latest
156187

157188
steps:
158189
- uses: actions/download-artifact@v3
159190

191+
- name: fixup requirements files
192+
# use sed to comment out the self references in requirements files
193+
run: sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements*.txt
194+
160195
- name: Github Release
161196
# We pin to the SHA, not the tag, for security reasons.
162197
# https://docs.github.com/en/actions/learn-github-actions/security-hardening-for-github-actions#using-third-party-actions

Dockerfile

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,36 +8,21 @@ FROM python:3.10 as build
88
# Add any system dependencies for the developer/build environment here
99
RUN apt-get update && apt-get upgrade -y && \
1010
apt-get install -y --no-install-recommends \
11-
build-essential \
1211
busybox \
13-
git \
14-
net-tools \
15-
vim \
1612
&& rm -rf /var/lib/apt/lists/* \
1713
&& busybox --install
1814

1915
COPY . /project
2016
WORKDIR /project
2117

22-
# make the wheel outside of the venv so 'build' does not dirty requirements.txt
23-
RUN pip install --upgrade pip build && \
24-
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
25-
git diff && \
26-
python -m build && \
27-
touch requirements.txt
28-
2918
# set up a virtual environment and put it in PATH
3019
RUN python -m venv /venv
3120
ENV PATH=/venv/bin:$PATH
3221

33-
# install the wheel and generate the requirements file
22+
# install the wheel
3423
RUN pip install --upgrade pip && \
35-
pip install -r requirements.txt dist/*.whl && \
36-
mkdir -p lockfiles && \
37-
pip freeze > lockfiles/requirements.txt && \
38-
# we don't want to include our own wheel in requirements - remove with sed
39-
# and replace with a comment to avoid a zero length asset upload later
40-
sed -i '/file:/s/^/# Requirements for /' lockfiles/requirements.txt
24+
touch requirements.txt && \
25+
pip install -r requirements.txt dist/*.whl
4126

4227
FROM python:3.10-slim as runtime
4328

0 commit comments

Comments
 (0)