-
-
Notifications
You must be signed in to change notification settings - Fork 324
Implement Docker container build and publish actions #1086
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
d-mcknight
wants to merge
20
commits into
TheSpaghettiDetective:master
Choose a base branch
from
d-mcknight:FEAT_DockerBuildAutomation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e2b6170
Implement ml_api container build via GHA
44f452c
Fix typo in GHA workflows directory
c0925d0
Fix errors in docker workflow
9ae1c42
Remove caching causing GHA failure
0a06b51
Setup QEMU and buildx for arm64 build support
9cec66a
Fix missing `repo_owner` in image name
245f8b8
Update backend container build and docker-compose
3dccc0f
Fix GHA Docker metadata step ids
9949300
Fix Dockerfile context used in backend build
a90dfee
Update command handling in web/tasks containers
4a6d507
Mount `/data` directory for sqlite database and media recordings
fc88f03
Troubleshooting media mount path
3360e7d
Fix typo in Dockerfile directory creation
22c2dcc
Move media directory creation to run.sh script to troubleshoot errors
d520d9d
Refactor media directory linking to prevent interference with static …
adf7a00
Troubleshoot media directory creation
1c4c38c
Refactor `media` directory handling
94bddbf
Remove commented-out lines from docker-compose
8583e8e
Implement Docker build caching and update docker-compose references
beb028c
Update docs and lowercase image names and note they should be updated…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| name: Build Docker Images | ||
| on: | ||
| workflow_dispatch: | ||
| push: | ||
| branches: | ||
| - master | ||
| - release | ||
|
|
||
| env: | ||
| REGISTRY: ghcr.io | ||
| PLATFORMS: linux/amd64,linux/arm64 | ||
| jobs: | ||
| build_and_publish_docker: | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| packages: write | ||
| steps: | ||
| # Clone the repository | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.ref }} | ||
| fetch-depth: 1 | ||
|
|
||
| # Configure Docker Buildx for cross-platform builds | ||
| - name: Setup QEMU | ||
| uses: docker/setup-qemu-action@v2 | ||
| - name: Setup Docker Buildx | ||
| uses: docker/setup-buildx-action@v2 | ||
|
|
||
| # Log into ghcr | ||
| - name: Log in to the Container registry | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ${{ env.REGISTRY }} | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| # ml_api image | ||
| - name: Extract metadata for ml_api | ||
| uses: docker/metadata-action@v2 | ||
| id: ml_meta | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{github.repository_owner}}/ml_api | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=raw,value=latest | ||
|
|
||
| - name: Build and push ml_api Docker image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: ml_api | ||
| push: true | ||
| tags: ${{ steps.ml_meta.outputs.tags }} | ||
| labels: ${{ steps.ml_meta.outputs.labels }} | ||
| platforms: ${{ env.PLATFORMS }} | ||
| file: ml_api/Dockerfile | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max | ||
|
|
||
| # obico_web image | ||
| - name: Extract metadata for obico_web | ||
| uses: docker/metadata-action@v2 | ||
| id: web_meta | ||
| with: | ||
| images: ${{ env.REGISTRY }}/${{github.repository_owner}}/obico_web | ||
| tags: | | ||
| type=ref,event=branch | ||
| type=raw,value=latest | ||
|
|
||
| - name: Build and push obico_web Docker image | ||
| uses: docker/build-push-action@v5 | ||
| with: | ||
| context: . | ||
| push: true | ||
| tags: ${{ steps.web_meta.outputs.tags }} | ||
| labels: ${{ steps.web_meta.outputs.labels }} | ||
| platforms: ${{ env.PLATFORMS }} | ||
| file: backend/Dockerfile | ||
| cache-from: type=gha | ||
| cache-to: type=gha,mode=max |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/bin/sh | ||
| set -e | ||
|
|
||
| OBICO_CONTAINER=${OBICO_CONTAINER:-$1} | ||
| if [ "${OBICO_CONTAINER}" = "tasks" ]; then | ||
| celery -A config worker --beat -l info -c 2 -Q realtime,celery | ||
| elif [ "${OBICO_CONTAINER}" = "web" ]; then | ||
| python manage.py migrate | ||
| python manage.py collectstatic -v 2 --noinput | ||
|
|
||
| # Implementation from https://github.com/imagegenius/docker-obico | ||
| [ -d /data/media ] || mkdir /data/media | ||
| [ -d /app/static_build/media ] && rm -r /app/static_build/media | ||
| ln -s /data/media /app/static_build/media | ||
|
|
||
| daphne -b 0.0.0.0 -p 3334 config.routing:application | ||
| fi | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,12 +40,12 @@ git clone -b release https://github.com/TheSpaghettiDetective/obico-server.git | |
| cd obico-server && docker-compose up -d | ||
| ``` | ||
|
|
||
| This will install obico-server to your Unraid server! To update obico-server, open up the terminal, change directory to the install directory, and run docker compose again. | ||
| This will install obico-server to your Unraid server! To update obico-server, open up the terminal, change directory to the install directory, and run `docker compose pull`. | ||
|
|
||
| ```Bash | ||
| cd /mnt/user/appdata/obico-server # or where you install obico-server to | ||
| git pull | ||
| docker-compose up -d --force-recreate --build | ||
| docker compose pull | ||
| docker compose up -d --force-recreate --build | ||
| ``` | ||
|
|
||
| ## Configuring obico-server {#configuring-obico} | ||
|
|
@@ -69,12 +69,6 @@ [email protected] | |
| ... | ||
| ``` | ||
|
|
||
| Rebuild the container (Note - if you are going to limit the CPU usage you can also change that now before rebuilding the container, see the below section) - | ||
|
|
||
| ```bash | ||
| docker-compose up -d --force-recreate --build | ||
| ``` | ||
|
|
||
| ## Issues with the Installation {#issues-with-the-installation} | ||
|
|
||
| Unlike most containers that you install to Unraid, containers installed with Docker-Compose are limited in what you can do with them through the GUI. You cannot update them, change their logo, description, or do anything except for stop and restart them through the GUI. When you update the containers, you must remove the old and outdated ones manually from the command line using `docker image rm`. | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove everything here every time the server starts?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I updated the compose file to mount the
/datadirectory so that a user can specify where on their host system to save recordings and to keep user data separated from code.The line after this creates a symlink to
/datawhich is where I also put the sqlite db by defaultThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I'm following. My question is if everything in /app/static_build/media (which I believe will include timelapses etc) will be erased every time
run.shruns.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the
static_buildfiles are built on container start; I just kept the existing logic to minimize changes. With this PR, I moved the timelapses to/data/mediawhich is linked to/app/static_build/mediaon line 14; the directory is removed on line 13 so that the link may be created.I made this change so that
/appdoesn't need to be mounted on the host FS. The files will not be erased, because they are mounted to the container at/data/media.Related, I might be able to simplify the container startup and drop some of this logic if
python manage.py collectstaticcan be run beforepython manage.py migrate, but I don't know enough about what those processes are doing to say if that would work.