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

Commit 853c2ef

Browse files
committed
container build and push with inverse conditions
1 parent 888e60e commit 853c2ef

File tree

3 files changed

+28
-44
lines changed

3 files changed

+28
-44
lines changed

.github/workflows/code.yml

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ on:
77
# Run every Monday at 8am to check latest versions of dependencies
88
- cron: "0 8 * * WED"
99
env:
10-
# the target python version. Make sure the Dockerfile uses the same
11-
# version for its build and runtime targets.
10+
# Target python version. Make sure Dockerfile FROM's match this.
1211
PYTHON: "3.10"
1312

1413
jobs:
@@ -24,12 +23,12 @@ jobs:
2423
- name: Setup python
2524
uses: actions/setup-python@v4
2625
with:
27-
python-version: ${{env.PYTHON}}
26+
python-version: ${{ env.PYTHON }}
2827

2928
- name: Lint
3029
run: |
31-
touch requirements_dev.txt requirements.txt
32-
pip install -r requirements.txt -r requirements_dev.txt -e .[dev]
30+
touch requirements_dev_py${{ env.PYTHON }}.txt requirements.txt
31+
pip install -r requirements.txt -r requirements_dev_py${{ env.PYTHON }}.txt -e .[dev]
3332
tox -e pre-commit,mypy
3433
3534
test:
@@ -60,7 +59,7 @@ jobs:
6059
run: |
6160
pip install .[dev]
6261
mkdir -p lockfiles
63-
pip freeze > lockfiles/requirements-dev-py${{ matrix.python }}.txt
62+
pip freeze > lockfiles/requirements_dev_py${{ matrix.python }}.txt
6463
6564
- name: Run tests
6665
run: pytest tests
@@ -90,12 +89,12 @@ jobs:
9089
- name: Setup python
9190
uses: actions/setup-python@v4
9291
with:
93-
python-version: ${{env.PYTHON}}
92+
python-version: ${{ env.PYTHON }}
9493

9594
- name: Build Sdist and wheel
9695
run: |
9796
export SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
98-
pipx run --python $(which python${{env.PYTHON}}) build
97+
pipx run --python $(which python${{ env.PYTHON }}) build
9998
10099
# ${GITHUB_REPOSITORY##*/} is the repo name without org
101100
# Replace this with the cli command if different to the repo name
@@ -124,7 +123,6 @@ jobs:
124123

125124
container:
126125
needs: [dist]
127-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.repository
128126
runs-on: ubuntu-latest
129127

130128
permissions:
@@ -137,11 +135,11 @@ jobs:
137135
with:
138136
fetch-depth: 0
139137

140-
- uses: actions/download-artifact@v3
138+
# image names must be all lower case
139+
- run: |
140+
echo IMAGE_REPOSITORY=ghcr.io/$(tr '[:upper:]' '[:lower:]' <<< "${{ github.repository }}") >> $GITHUB_ENV
141141
142-
- name: PrepareReg Names
143-
run: |
144-
echo IMAGE_REPOSITORY=ghcr.io/$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]') >> $GITHUB_ENV
142+
- uses: actions/download-artifact@v3
145143

146144
- name: Log in to GitHub Docker Registry
147145
if: github.event_name != 'pull_request'
@@ -155,7 +153,7 @@ jobs:
155153
id: meta
156154
uses: docker/metadata-action@v4
157155
with:
158-
images: ${{env.IMAGE_REPOSITORY}}
156+
images: ${{ env.IMAGE_REPOSITORY }}
159157
tags: |
160158
type=ref,event=tag
161159
type=raw,value=latest
@@ -167,22 +165,21 @@ jobs:
167165
- name: Build runtime image
168166
uses: docker/build-push-action@v3
169167
with:
170-
push: true
171-
load: true
168+
push: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
169+
load: ${{ ! (github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) }}
172170
tags: ${{ steps.meta.outputs.tags }}
173171
context: .
172+
cache-from: type=gha
173+
cache-to: type=gha,mode=max
174174

175175
- name: Test cli works in runtime image
176-
# check that the first tag can run with --version parameter
177-
run: docker run ${{env.IMAGE_REPOSITORY}}:latest --version
178-
179-
# TODO upload a tar of the image for later publishing
180-
# TODO OR do the publish here ??? if its quick enough - MUCH easier ?
176+
# check that the latest tag can run with --version parameter
177+
run: docker run ${{ env.IMAGE_REPOSITORY }} --version
181178

182179
release:
183180
# upload to PyPI and make a release on every tag
184-
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
185181
needs: [lint, dist]
182+
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
186183
runs-on: ubuntu-latest
187184

188185
steps:

.github/workflows/container_tests.sh

Lines changed: 0 additions & 14 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#
66
FROM python:3.10 as build
77

8-
# Add any system dependencies for the developer/build environment here
9-
RUN apt-get update && apt-get upgrade -y && \
10-
apt-get install -y --no-install-recommends \
11-
busybox \
12-
&& rm -rf /var/lib/apt/lists/* \
13-
&& busybox --install
8+
# Add any system dependencies for the developer/build environment here e.g.
9+
# RUN apt-get update && apt-get upgrade -y && \
10+
# apt-get install -y --no-install-recommends \
11+
# busybox \
12+
# && rm -rf /var/lib/apt/lists/* \
13+
# && busybox --install
1414

1515
COPY . /project
1616
WORKDIR /project
@@ -20,8 +20,9 @@ RUN python -m venv /venv
2020
ENV PATH=/venv/bin:$PATH
2121

2222
# install the wheel
23-
RUN pip install --upgrade pip && \
24-
touch requirements.txt && \
23+
RUN touch requirements.txt && \
24+
for i in requirements.txt .gitignore lockfiles; do echo $i >> .gitignore; done && \
25+
git diff && \
2526
pip install -r requirements.txt dist/*.whl
2627

2728
FROM python:3.10-slim as runtime

0 commit comments

Comments
 (0)