Skip to content

Commit 4995b1e

Browse files
fix: fix distroless container and update ci
This includes more requirements in the distroless container for git and updates CI and the actionfile to better use docker images. This will also move to pushing images to ghcr
1 parent ef79875 commit 4995b1e

File tree

7 files changed

+145
-102
lines changed

7 files changed

+145
-102
lines changed

.github/workflows/integration.yml renamed to .github/workflows/action-integration.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,28 @@
1-
name: Integration Test
1+
# Tests athe github action on each push
2+
name: Action Integration Test
23
on:
34
push:
4-
branches:
5-
- main
65
pull_request:
76
jobs:
8-
integration-testing:
9-
name: Integration Testing
7+
action-integration-testing:
8+
name: Action Integration Testing
109
runs-on: ubuntu-latest
1110
steps:
1211
- uses: actions/checkout@v3
1312
name: Checkout
14-
- name: Copy in Dockerfile
15-
run: cp Docker/Dockerfile Dockerfile
13+
- name: Set up Docker Buildx
14+
uses: docker/setup-buildx-action@v2
15+
- name: Update action.yml to use dockerfile
16+
uses: rmeneely/update-yaml@v1
17+
with:
18+
infile: action.yml
19+
varlist: "runs.image=Dockerfile"
1620
- name: Test action
1721
id: test-action
1822
# test with the local checkout of the action
1923
uses: ./
2024
with:
21-
template: https://github.com/cjolowicz/cookiecutter-hypermodern-python
25+
template: https://github.com/cjolowicz/cookiecutter-hypermodern-python.git
2226
cookiecutterValues: '{
2327
"project_name": "integration-test"
2428
}'
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Runs after release-please creates a new release
2+
# Builds and pushes the docker images for the release
3+
name: Release Docker Images
4+
on:
5+
release:
6+
types: [released]
7+
8+
jobs:
9+
build-and-push-dockerimage:
10+
name: Buld and push dockerimage
11+
if: github.repository_owner == 'andrewthetechie'
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up QEMU
16+
uses: docker/setup-qemu-action@v2
17+
- name: Set up Docker Buildx
18+
uses: docker/setup-buildx-action@v2
19+
- name: Login to DockerHub
20+
uses: docker/login-action@v2
21+
with:
22+
username: ${{ secrets.DOCKERHUB_USERNAME }}
23+
password: ${{ secrets.DOCKERHUB_TOKEN }}
24+
- name: Log in to the Container registry
25+
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.THIS_PAT }}
30+
- name: Docker metadata
31+
uses: docker/metadata-action@v4
32+
id: meta
33+
with:
34+
images: |
35+
${{ github.repository }}
36+
ghcr.io/${{ github.repository }}
37+
tags: |
38+
type=raw,value=${{ github.ref_name }}
39+
# minimal (short sha)
40+
type=sha,prefix=
41+
# full length sha
42+
type=sha,format=long,prefix=
43+
- name: Build and push
44+
id: docker_build
45+
uses: docker/build-push-action@v3
46+
with:
47+
context: .
48+
file: Dockerfile
49+
push: true
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}
52+
platforms: linux/amd64,linux/arm64
53+
# https://github.com/docker/build-push-action/blob/master/docs/advanced/cache.md#registry-cache
54+
cache-from: type=gha
55+
cache-to: type=gha,mode=max
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Updates major version tag for GHA ease of use
2+
name: Update Major Version Tag
3+
4+
on:
5+
push:
6+
tags:
7+
- "v*"
8+
9+
jobs:
10+
update-majorver:
11+
name: Update Major Version Tag
12+
if: github.repository_owner == 'andrewthetechie'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: nowactions/update-majorver@v1

.github/workflows/release-please.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ on:
55
name: release-please
66
jobs:
77
release-please:
8+
if: github.repository_owner == 'andrewthetechie'
89
runs-on: ubuntu-latest
910
steps:
1011
- uses: google-github-actions/release-please-action@v3
1112
with:
1213
token: ${{ secrets.THIS_PAT }}
13-
release-type: simple
14+
release-type: python
15+
extra-files: |
16+
action.yml

.github/workflows/release.yml

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

Dockerfile

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1-
# This file is generated from Docker/ActionDockerfile.j2 as part of the release ci
2-
# Don't modify it directly
3-
FROM andrewthetechie/gha-cookiecutter:v1.2.0
1+
# Distroless runs python 3.9.2
2+
FROM python:3.11-slim-bullseye as python-base
3+
ADD Docker/builder/rootfs /
4+
ADD main.py /app/main.py
5+
ADD action.yml /app/action.yml
6+
7+
# We are installing a dependency here directly into our app source dir
8+
RUN pip install --target=/app -r /requirements.txt
9+
RUN cd /tmp && \
10+
apt-get update && \
11+
apt-get download git $(apt-cache depends --recurse --no-recommends --no-suggests \
12+
--no-conflicts --no-breaks --no-replaces --no-enhances \
13+
--no-pre-depends git | grep "^\w") libcurl3-gnutls $(apt-cache depends --recurse --no-recommends --no-suggests \
14+
--no-conflicts --no-breaks --no-replaces --no-enhances \
15+
--no-pre-depends libcurl3-gnutls | grep "^\w") && \
16+
mkdir /dpkg && \
17+
for deb in *.deb; do dpkg --extract $deb /dpkg || exit 10; done
18+
19+
# use distroless/cc as the base for our final image
20+
# lots of python depends on glibc
21+
FROM gcr.io/distroless/cc-debian11
22+
23+
# Copy python from the python-builder
24+
# this carries more risk than installing it fully, but makes the image a lot smaller
25+
COPY --from=python-base /usr/local/lib/ /usr/local/lib/
26+
COPY --from=python-base /usr/local/bin/python /usr/local/bin/python
27+
COPY --from=python-base /etc/ld.so.cache /etc/ld.so.cache
28+
29+
# Add some common compiled libraries
30+
# If seeing ImportErrors, check if in the python-base already and copy as below
31+
# required by lots of packages - e.g. six, numpy, wsgi
32+
# *-linux-gnu makes this builder work with either linux/arm64 or linux/amd64
33+
COPY --from=python-base /lib/*-linux-gnu/libz.so.1 /lib/libs/
34+
COPY --from=python-base /lib/*-linux-gnu/libcom_err.so.2 /lib/libs/
35+
COPY --from=python-base /usr/lib/*-linux-gnu/libffi* /lib/libs/
36+
COPY --from=python-base /lib/*-linux-gnu/libexpat* /lib/libs/
37+
38+
# Add some git libs
39+
COPY --from=python-base /lib/*-linux-gnu/libcom_err.so.2 /lib/libs/
40+
41+
# Copy over the app
42+
COPY --from=python-base /app /app
43+
COPY --from=python-base /dpkg /
44+
WORKDIR /app
45+
46+
# Add /lib/libs to our path
47+
ENV LD_LIBRARY_PATH="/lib/libs:${LD_LIBRARY_PATH}" \
48+
# Add the app path to our path
49+
PATH="/app/bin:${PATH}" \
50+
# Add the app path to your python path
51+
PYTHONPATH="/app:${PYTHONPATH}" \
52+
# standardise on locale, don't generate .pyc, enable tracebacks on seg faults
53+
LANG=C.UTF-8 \
54+
LC_ALL=C.UTF-8 \
55+
PYTHONDONTWRITEBYTECODE=1 \
56+
PYTHONFAULTHANDLER=1
57+
58+
CMD ["python", "/app/main.py"]

action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ outputs:
3939
description: "Directory the cookiecutter outputted to"
4040
runs:
4141
using: "docker"
42-
image: "Dockerfile"
42+
image: "docker://ghcr.io/andrewthetechie/gha-cookiecutter:v1.3.0" # x-release-please-version
4343
branding:
4444
icon: 'layers'
4545
color: 'blue'

0 commit comments

Comments
 (0)