Skip to content

Commit e0cfba4

Browse files
committed
first commit
0 parents  commit e0cfba4

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Ignore everything
2+
**

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Robert Hafner
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Python Image Builder - Github Action

action.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: 'Multi-Py Image Builder'
2+
description: 'Build multiarchitecture builds of your favorite Python libraries.'
3+
4+
inputs:
5+
6+
python_version:
7+
description: 'The Python version for this container.'
8+
required: true
9+
default: '3.10'
10+
11+
target_base:
12+
description: 'The target version (slim, alpine, or full)'
13+
required: true
14+
default: 'full'
15+
16+
package:
17+
description: 'The primary python package for the container.'
18+
required: true
19+
20+
package_version:
21+
description: 'The version to use in this container.'
22+
required: true
23+
24+
package_latest_version:
25+
description: 'The latest version of the package. When this matches `package_version` extra tags are added.'
26+
required: false
27+
28+
image_name:
29+
description: 'The name of the image (without the registry or tag).'
30+
required: true
31+
default: ${{ github.repository }}
32+
33+
platform:
34+
description: 'The platform string to pass to buildx.'
35+
required: true
36+
default: "linux/amd64,linux/arm64,linux/arm/v7"
37+
38+
maintainer:
39+
description: 'The maintainer, in `Name <email>` format.'
40+
required: true
41+
default: ${{ github.repository_owner }}
42+
43+
dockerfile:
44+
description: "The path to the dockerfile to use while building."
45+
required: true
46+
default: "${{ github.action_path }}/dockerfile"
47+
48+
docker_context:
49+
description: "The context for building the image."
50+
required: true
51+
default: "${{ github.workspace }}/"
52+
53+
registry:
54+
description: "The registry to store the image in."
55+
required: true
56+
default: "ghcr.io"
57+
58+
registry_username:
59+
description: "The username for logging into the registry. For the Github registry the repository owner is typically the username."
60+
required: true
61+
default: ${{ github.repository_owner }}
62+
63+
registry_password:
64+
description: "The password for logging into the registry. For the Github registry the repository owner is typically `secret.GITHUB_TOKEN`."
65+
required: true
66+
67+
68+
69+
runs:
70+
using: "composite"
71+
steps:
72+
73+
- name: Set up QEMU
74+
uses: docker/setup-qemu-action@v1
75+
76+
- name: Set up Docker Buildx
77+
id: buildx
78+
uses: docker/setup-buildx-action@v1
79+
80+
- name: Log in to the Container registry
81+
uses: docker/login-action@v1
82+
with:
83+
registry: ${{ inputs.registry }}
84+
username: ${{ inputs.registry_username }}
85+
password: ${{ inputs.registry_password }}
86+
87+
- name: Deploy Image
88+
run: bash ${{ github.action_path }}/scripts/build_and_push.sh
89+
shell: bash
90+
env:
91+
DOCKERFILE_LOCATION: ${{ inputs.dockerfile }}
92+
DOCKER_CONTEXT: ${{ inputs.docker_context }}
93+
PYTHON_VERSION: ${{ inputs.python_version }}
94+
TARGET_BASE: ${{ inputs.target_base }}
95+
PACKAGE_LIST: ${{ inputs.package_list }}
96+
PLATFORM: ${{ inputs.platform }}
97+
PACKAGE: ${{ inputs.package }}
98+
PACKAGE_VERSION: ${{ inputs.package_version }}
99+
PACKAGE_LATEST_VERSION: ${{ inputs.package_latest_version }}
100+
MAINTAINER: ${{ inputs.maintainer }}

dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
ARG python_version=3.9
2+
ARG build_target=$python_version
3+
ARG publish_target=$python_version
4+
5+
FROM python:$build_target as Builder
6+
7+
# Add arguments to container scope
8+
ARG build_target
9+
ARG package
10+
ARG package_version
11+
12+
# Only add build tools for alpine image. The ubuntu based images have build tools already.
13+
RUN if [[ "$build_target" == *"alpine" ]] ; then apk add build-base ; fi
14+
15+
# Install packaer and build all dependencies.
16+
RUN pip install $package==$package_version
17+
18+
# Build our actual container now.
19+
FROM python:$publish_target
20+
21+
# Add args to container scope.
22+
ARG python_version
23+
ARG package
24+
ARG maintainer=""
25+
LABEL python=$version
26+
LABEL package=$package
27+
LABEL maintainer=$maintainer
28+
29+
# Copy all of the python files built in the Builder container into this smaller container.
30+
COPY --from=Builder /usr/local/lib/python$python_version /usr/local/lib/python$python_version
31+

example.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
name: Example Image Builder - Uvicorn
3+
4+
on: [push]
5+
6+
jobs:
7+
Uvicorn-Builder:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
python_version: ["3.6", "3.7", "3.8", "3.9", "3.10"]
13+
package_versions: ["0.12.1", "0.12.2", "0.12.3", "0.13.0", "0.13.1", "0.13.2", "0.13.3", "0.13.4", "0.14.0", "0.15.0"]
14+
target_base: ["full", "slim", "alpine"]
15+
steps:
16+
- name: "Create and push"
17+
uses: multi-py/action-python-image-builder@main
18+
with:
19+
package: "uvicorn"
20+
package_latest_version: "0.15.0"
21+
maintainer: "Myname <user@example.com>"
22+
python_version: ${{ matrix.python_version }}
23+
target_base: ${{ matrix.target_base }}
24+
package_version: ${{ matrix.package_versions }}
25+
registry_password: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)