Skip to content

Commit 0d97899

Browse files
authored
Merge pull request #14 from dev-dull/6_dockerize
6 dockerize
2 parents f36a0d0 + 0f3feb1 commit 0d97899

6 files changed

Lines changed: 84 additions & 2 deletions

File tree

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Build Docker Image
2+
on:
3+
schedule:
4+
# Refresh monthly to pick up base image updates
5+
# Base image refreshes on the 1st, so run on the 2nd to capture upstream changes.
6+
- cron: '0 0 2 * *'
7+
push:
8+
branches:
9+
- main
10+
jobs:
11+
build:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- uses: anothrNick/github-tag-action@1.71.0
17+
id: bump_version
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
20+
DEFAULT_BUMP: patch
21+
WITH_V: true
22+
23+
- uses: docker/login-action@v3
24+
with:
25+
username: ${{ secrets.DOCKERHUB_USERNAME }}
26+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
27+
28+
- uses: docker/setup-qemu-action@v3
29+
30+
- uses: docker/setup-buildx-action@v3
31+
32+
- uses: docker/metadata-action@v5
33+
id: docker_meta
34+
with:
35+
images: |
36+
devdull/${{ github.event.repository.name }}
37+
tags: |
38+
# Tag branches with branch name, but disable for default branch
39+
type=ref,event=branch,enable=${{ github.ref_name != 'main' }}
40+
# set latest tag for default branch
41+
type=raw,value=latest,enable=${{ github.ref_name == 'main' }}
42+
# Always tag with the current version number
43+
type=raw,value=${{ steps.bump_version.outputs.new_tag }},enable=${{ github.ref_name == 'main' }}
44+
45+
- uses: docker/build-push-action@v5
46+
id: docker_build
47+
with:
48+
platforms: linux/amd64,linux/arm,linux/arm64
49+
push: ${{ github.repository_owner == 'dev-dull' }}
50+
tags: ${{ steps.docker_meta.outputs.tags }}
51+
labels: ${{ steps.docker_meta.outputs.labels }}

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM python:3-slim AS builder
2+
3+
COPY requirements.txt .
4+
RUN pip install --user -r requirements.txt
5+
6+
FROM python:3-slim
7+
8+
ARG LISTEN_PORT=8000
9+
ENV LISTEN_PORT=${LISTEN_PORT}
10+
11+
RUN mkdir /app
12+
WORKDIR /app
13+
14+
COPY --from=builder /root/.local /root/.local
15+
COPY ddb.py pyxie.py constfig.py config.yaml run.sh ./
16+
ENV PATH=/root/.local/bin:$PATH
17+
18+
EXPOSE ${LISTEN_PORT}
19+
CMD ["/app/run.sh"]

constfig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class _C(object):
1010
def __init__(self):
1111
# Default values for user configurable items
12-
self.LISTEN_IP = "0.0.0.0"
12+
self.LISTEN_IP = "127.0.0.1"
1313
self.LISTEN_PORT = 5000
1414
self.API_KEYS = []
1515
self.LOG_LEVEL = "WARNING"

pyxie.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def root():
5757

5858

5959
def main():
60-
pyxie.run()
60+
pyxie.run(host=C.LISTEN_IP, port=C.LISTEN_PORT)
6161

6262

6363
if __name__ == "__main__":

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
pyyaml
22
flask
33
ua-parser
4+
gunicorn

run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
if [ -z "$LISTEN_IP" ]; then
4+
export LISTEN_IP="0.0.0.0"
5+
fi
6+
7+
if [ -z "$LISTEN_PORT" ]; then
8+
export LISTEN_PORT=8000
9+
fi
10+
11+
gunicorn --bind $LISTEN_IP:$LISTEN_PORT pyxie:pyxie

0 commit comments

Comments
 (0)