Skip to content

Commit

Permalink
Added github actions automagic docker containers build workflow (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
HetorusNL authored Aug 25, 2023
1 parent 8c7d536 commit bb8c519
Show file tree
Hide file tree
Showing 15 changed files with 354 additions and 116 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/dockerhub-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Update Dockerhub Description

on:
push:
branches:
- master
paths:
- README.md
- .github/workflows/dockerhub-description.yml

jobs:
update-docker-hub-description:
runs-on: ubuntu-latest

steps:
# checkout the repo to $GITHUB_WORKSPACE
- uses: actions/checkout@v3

# update the docker hub description and overview
- name: Dockerhub description and overview update
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: hetorusnl/vocya-api
short-description: ${{ github.event.repository.description }}

# update the docker hub description and overview
- name: Dockerhub description and overview update
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
repository: hetorusnl/vocya-dashboard
short-description: ${{ github.event.repository.description }}
59 changes: 59 additions & 0 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Master branch CI/CD

on:
push:

jobs:
build-and-push-container:
runs-on: ubuntu-latest

steps:
# checkout the repo to $GITHUB_WORKSPACE
- uses: actions/checkout@v3

# login to docker hub
- name: Login to Dockerhub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# login to github container registry
- name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# build and push the vocya api docker image to ghcr.io
- name: Build and Push Image to ghcr.io
run: ./gha/build-container.sh
env:
CI_REGISTRY: ghcr.io/hetorusnl/vocya-api
DOCKERFILE: api.Dockerfile
BRANCH_NAME: ${{ github.ref_name }}

# build and push the vocya api docker image to docker hub
- name: Build and Push Image to Dockerhub
run: ./gha/build-container.sh
env:
CI_REGISTRY: hetorusnl/vocya-api
DOCKERFILE: api.Dockerfile
BRANCH_NAME: ${{ github.ref_name }}

# build and push the vocya dashboard docker image to ghcr.io
- name: Build and Push Image to ghcr.io
run: ./gha/build-container.sh
env:
CI_REGISTRY: ghcr.io/hetorusnl/vocya-dashboard
DOCKERFILE: dashboard.Dockerfile
BRANCH_NAME: ${{ github.ref_name }}

# build and push the vocya dashboard docker image to docker hub
- name: Build and Push Image to Dockerhub
run: ./gha/build-container.sh
env:
CI_REGISTRY: hetorusnl/vocya-dashboard
DOCKERFILE: dashboard.Dockerfile
BRANCH_NAME: ${{ github.ref_name }}
5 changes: 0 additions & 5 deletions .vscode/settings.json

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Tim Klein Nijenhuis <tim@hetorus.nl>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Install the required dependencies:
`cd api`
`poetry install`

Modify the path to the VocJEM database file in `database_file` in `api.py`, if that repository is stored in a different location.
Modify the path to the VocJEM database file in `database_file` in `main.py`, if that repository is stored in a different location.

Run the API
`cd api`
`poetry run python3 api.py`
`poetry run python3 main.py`

### Example queries

Expand Down Expand Up @@ -105,3 +105,7 @@ these three commands also perform a push to the master branch on github and push
run the following command to deploy the new version:
`yarn deploy`
this removes the previous build from the server and copies the build to the server

## License

MIT License, Copyright (c) 2023 Tim Klein Nijenhuis <tim@hetorus.nl>
12 changes: 12 additions & 0 deletions api.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM hetorusnl/python-poetry

# add the api python files to the docker
COPY api/ /code

# add/update the container labels
LABEL org.label-schema.vcs-ref=$VCS_REF
LABEL org.label-schema.vcs-url=https://github.com/HetorusNL/vocya
LABEL org.opencontainers.image.authors=tim@hetorus.nl
LABEL org.opencontainers.image.source=https://github.com/HetorusNL/vocya
LABEL org.opencontainers.image.description="Vocya API for learning Japanese words"
LABEL org.opencontainers.image.licenses=MIT
29 changes: 0 additions & 29 deletions api/db_watcher.py

This file was deleted.

22 changes: 9 additions & 13 deletions api/api.py → api/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from flask import Flask, jsonify

from vocabulary_db import VocabularyDB
from db_watcher import DBWatcher

api = Flask(__name__)

Expand Down Expand Up @@ -104,19 +103,16 @@ def word(wo_id):
return jsonify(word)


if __name__ == "__main__":
database_file = "/opt/vocjem/dictionary.json"
@api.route("/update-database")
def update_database():
_vocabulary_db.update()
return jsonify({"result": "success"})


if __name__ == "__main__":
# initialize the vocabulary database
_vocabulary_db = VocabularyDB(database_file)
_vocabulary_db = VocabularyDB()
_vocabulary_db.update()

# initialize the DB watcher that updates the database on file system events
_db_watcher = DBWatcher(database_file, _vocabulary_db)
_db_watcher.watch()

# run the api and when stopped/crashed stop the watcher
try:
api.run()
finally:
_db_watcher.stop()
# run the api as a blocking call
api.run(host="0.0.0.0")
Loading

0 comments on commit bb8c519

Please sign in to comment.