Skip to content

Commit

Permalink
Merge branch 'dockerize'
Browse files Browse the repository at this point in the history
  • Loading branch information
brentvollebregt committed Nov 24, 2023
2 parents 2ba6da6 + 9a6c0ed commit 743e50b
Show file tree
Hide file tree
Showing 38 changed files with 841 additions and 823 deletions.
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.github
.venv
.vscode
webapp/build
webapp/node_modules
whos_on_my_network/static
**/__pycache__
.env
.env.example
.gitignore
.prettierrc
database.sqlite
README.md
run.py
Dockerfile
docker-compose.dev.yml
docker-compose.yml
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DATABASE_PATH=./database.sqlite
PORT=8080
SCANNER=default
NETWORK_ID=192.168.1.0/24
50 changes: 50 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and Publish Docker Image

on:
workflow_dispatch:
push:
branches:
- master

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Log in to the Container registry
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- uses: actions/delete-package-versions@v4
with:
owner: ${{ github.repository_owner }}
package-name: ${{ github.event.repository.name }}
package-type: "container"
min-versions-to-keep: 2
101 changes: 0 additions & 101 deletions .github/workflows/release.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.sqlite
config.json
__pycache__/
whos_on_my_network/static
whos_on_my_network/static
.env
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"recommendations": [
"ms-vscode.vscode-typescript-tslint-plugin",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"ms-python.black-formatter",
"ms-python.python"
]
}
9 changes: 6 additions & 3 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,24 @@
"type": "python",
"request": "launch",
"module": "whos_on_my_network",
"args": ["start"]
"args": ["start"],
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Watch Devices on Network (5min intervals)",
"type": "python",
"request": "launch",
"module": "whos_on_my_network",
"args": ["watch", "-t", "300", "-v"]
"args": ["watch", "-t", "300", "-v"],
"envFile": "${workspaceFolder}/.env"
},
{
"name": "Scan Current Devices",
"type": "python",
"request": "launch",
"module": "whos_on_my_network",
"args": ["current"]
"args": ["current"],
"envFile": "${workspaceFolder}/.env"
}
]
}
12 changes: 10 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{
"editor.formatOnSave": true,
"editor.rulers": [100],
"editor.rulers": [120],
"editor.tabSize": 2,
"editor.codeActionsOnSave": {
"source.fixAll.tslint": true
}
},
"python.defaultInterpreterPath": ".venv\\Scripts\\python.exe",
"search.exclude": {
"**/.venv": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter"
},
"black-formatter.args": ["--line-length", "120"]
}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
##### FRONTEND BUILDER
FROM node:16.13.1-alpine3.15 AS frontend_builder
WORKDIR /app

# Setup fake ./whos_on_my_network/static for the frontend postbuild to move into
RUN mkdir -p ./whos_on_my_network/static

COPY ./webapp ./webapp
RUN cd ./webapp && npm ci && npm run build


##### RUNNER
FROM python:3.9.18-alpine3.18 AS runner
WORKDIR /app

COPY . .
COPY --from=frontend_builder /app/whos_on_my_network/static ./whos_on_my_network/static

RUN pip install -r requirements.txt

EXPOSE 3000
ENV PORT 3000

ENTRYPOINT ["python", "-m", "whos_on_my_network"]
CMD ["start"]
Loading

0 comments on commit 743e50b

Please sign in to comment.