Skip to content

Commit b1980ed

Browse files
Initial commit
0 parents  commit b1980ed

File tree

5 files changed

+368
-0
lines changed

5 files changed

+368
-0
lines changed

.github/workflows/docker.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: Build Docker Container
2+
3+
on:
4+
push:
5+
branches: ['**']
6+
tags: ["*.*.*"]
7+
pull_request:
8+
branches: ["main"]
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: 'pythoncoderas/<name>'
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
get-image-name:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- run: echo "null"
23+
outputs:
24+
image: ${{ env.IMAGE_NAME }}
25+
build:
26+
runs-on: ubuntu-latest
27+
needs: [get-image-name]
28+
if: ${{ needs.get-image-name.outputs.image != 'pythoncoderas/<name>' }}
29+
permissions:
30+
contents: read
31+
packages: write
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
platform:
36+
- linux/amd64
37+
- linux/arm64
38+
39+
steps:
40+
- name: Checkout repository
41+
uses: actions/checkout@v3
42+
43+
- name: Set up Docker Buildx
44+
uses: docker/[email protected]
45+
46+
- name: Log into registry ${{ env.REGISTRY }}
47+
if: github.event_name != 'pull_request'
48+
uses: docker/[email protected]
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract Docker metadata
55+
id: meta
56+
uses: docker/[email protected]
57+
with:
58+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
59+
60+
- name: Build Docker image
61+
id: build
62+
uses: docker/[email protected]
63+
with:
64+
context: .
65+
labels: ${{ steps.meta.outputs.labels }}
66+
cache-from: type=gha
67+
cache-to: type=gha,mode=max
68+
platforms: ${{ matrix.platform }}
69+
provenance: true
70+
sbom: true
71+
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=${{ github.event_name != 'pull_request' }}
72+
73+
- name: Export digest
74+
if: ${{ github.event_name != 'pull_request' }}
75+
run: |
76+
mkdir -p /tmp/digests
77+
digest="${{ steps.build.outputs.digest }}"
78+
touch "/tmp/digests/${digest#sha256:}"
79+
- name: Upload digest
80+
if: ${{ github.event_name != 'pull_request' }}
81+
uses: actions/upload-artifact@v3
82+
with:
83+
name: digests
84+
path: /tmp/digests/*
85+
if-no-files-found: error
86+
retention-days: 1
87+
88+
merge:
89+
runs-on: ubuntu-latest
90+
if: ${{ github.event_name != 'pull_request' }}
91+
needs:
92+
- build
93+
permissions:
94+
packages: write
95+
steps:
96+
- name: Download digests
97+
uses: actions/download-artifact@v3
98+
with:
99+
name: digests
100+
path: /tmp/digests
101+
- name: Set up Docker Buildx
102+
uses: docker/setup-buildx-action@v3
103+
- name: Docker meta
104+
id: meta
105+
uses: docker/metadata-action@v5
106+
with:
107+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
108+
- name: Log into registry ${{ env.REGISTRY }}
109+
if: github.event_name != 'pull_request'
110+
uses: docker/[email protected]
111+
with:
112+
registry: ${{ env.REGISTRY }}
113+
username: ${{ github.actor }}
114+
password: ${{ secrets.GITHUB_TOKEN }}
115+
- name: Create manifest list and push
116+
working-directory: /tmp/digests
117+
run: |
118+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
119+
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
120+
- name: Inspect image
121+
run: |
122+
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
ARG PYTHON_VERSION=3.12
2+
3+
FROM alpine/git as clone
4+
5+
ARG GIT_REPO="Repo name"
6+
ARG GIT_OWNER=PythonCoderAS
7+
ARG GIT_CLONE_URL="https://github.com/${GIT_OWNER}/${GIT_REPO}.git"
8+
ARG GIT_BRANCH=master
9+
10+
RUN git clone --depth 1 --branch ${GIT_BRANCH} ${GIT_CLONE_URL} /app
11+
RUN rm -rf /app/.git
12+
13+
FROM python:${PYTHON_VERSION} as generate-requirements
14+
15+
# Path: /app
16+
COPY --from=clone /app /app
17+
WORKDIR /app
18+
19+
RUN ["pip", "install", "pipenv"]
20+
RUN ["sh", "-c", "pipenv requirements --dev > requirements.txt"]
21+
RUN ["rm", "Pipfile", "Pipfile.lock"]
22+
23+
FROM python:${PYTHON_VERSION} as build
24+
25+
# Path: /app
26+
WORKDIR /app
27+
28+
COPY --from=generate-requirements /app/requirements.txt ./
29+
30+
RUN ["python3", "-m", "venv", "/venv"]
31+
ENV PATH="/venv/bin:$PATH"
32+
RUN ["python3", "-m", "pip", "install", "-r", "requirements.txt"]
33+
34+
FROM python:${PYTHON_VERSION}-slim as final
35+
COPY --from=build /venv /venv
36+
COPY --from=clone /app /app
37+
WORKDIR /app
38+
ENV PATH="/venv/bin:$PATH"
39+
ENTRYPOINT [ "python3", "/app/bot.py" ]

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) 2024 PythonCoderAS
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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# dockerfile-template-pipenv
2+
Template for Pipenv-based Dockerfile
3+
4+
Delete everything above the dash and the dash itself when making a new repo. Make sure to replace `<name>` as necessary.
5+
6+
## Update order
7+
8+
1. Update the README
9+
2. Update the Dockerfile
10+
3. Update the workflow. **Note: The first two steps can be done in either order, but it is absolutely necessary to do the third step last.**
11+
12+
----
13+
14+
# <name> Docker
15+
16+
Source: https://github.com/PythonCoderAS/<original repo name>
17+
18+
## Running
19+
20+
```bash
21+
docker run ghcr.io/pythoncoderas/<name>
22+
```
23+
24+
## Prerequisites
25+
26+
Include any if needed, otherwise delete this section

0 commit comments

Comments
 (0)