-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from rtuszik/docker
feat: add docker for automatic updates
- Loading branch information
Showing
8 changed files
with
255 additions
and
102 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,10 @@ | ||
GITHUB_TOKEN=your_github_token | ||
# GitHub Configuration | ||
GITHUB_TOKEN=ghp_your_github_personal_access_token_here | ||
GITHUB_USERNAME=your_github_username | ||
LINKWARDEN_URL=your_linkwarden_api_url | ||
LINKWARDEN_TOKEN=your_linkwarden_api_token | ||
# Linkwarden Configuration | ||
LINKWARDEN_URL=https://your-linkwarden-instance.com | ||
LINKWARDEN_TOKEN=your_linkwarden_api_token_here | ||
|
||
#### FOR CRONTAB: #### | ||
COLLECTION_ID=30 | ||
CRON_SCHEDULE="0 6 * * *" # Cron Schedule (default is daily at 6am) |
This file contains 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,40 @@ | ||
name: StarWarden Build | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
workflow_dispatch: | ||
|
||
env: | ||
DOCKER_IMAGE: rtuszik/starwarden | ||
|
||
jobs: | ||
build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
file: ./Dockerfile | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ env.DOCKER_IMAGE }}:latest | ||
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache | ||
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max | ||
|
||
- name: Image digest | ||
run: echo ${{ steps.docker_build.outputs.digest }} |
This file contains 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 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,50 @@ | ||
FROM python:3.11-slim | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
ENV GITHUB_TOKEN="" | ||
Check warning on line 4 in Dockerfile GitHub Actions / build-and-pushSensitive data should not be used in the ARG or ENV commands
|
||
ENV GITHUB_USERNAME="" | ||
ENV LINKWARDEN_URL="" | ||
ENV LINKWARDEN_TOKEN="" | ||
Check warning on line 7 in Dockerfile GitHub Actions / build-and-pushSensitive data should not be used in the ARG or ENV commands
|
||
ENV COLLECTION_ID="" | ||
ENV CRON_SCHEDULE="0 6 * * *" | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && apt-get install -y cron && rm -rf /var/lib/apt/lists/* | ||
|
||
COPY . . | ||
|
||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
# Create a cron job file | ||
RUN echo '#!/bin/sh' > /app/cron_job.sh && \ | ||
echo 'set -a' >> /app/cron_job.sh && \ | ||
echo '. /app/.env' >> /app/cron_job.sh && \ | ||
echo 'set +a' >> /app/cron_job.sh && \ | ||
echo 'if [ -n "$COLLECTION_ID" ]; then' >> /app/cron_job.sh && \ | ||
echo ' /usr/local/bin/python /app/starwarden.py -id "$COLLECTION_ID" >> /app/starwarden.log 2>&1' >> /app/cron_job.sh && \ | ||
echo 'else' >> /app/cron_job.sh && \ | ||
echo ' echo "Error: COLLECTION_ID is not set" >> /app/starwarden.log' >> /app/cron_job.sh && \ | ||
echo 'fi' >> /app/cron_job.sh && \ | ||
chmod +x /app/cron_job.sh | ||
|
||
|
||
# Create the log file to be able to run tail | ||
RUN touch /app/starwarden.log | ||
|
||
# Create start script | ||
RUN echo '#!/bin/sh' > /app/start.sh && \ | ||
echo 'env | grep -v "PATH\|HOSTNAME\|HOME" > /app/.env' >> /app/start.sh && \ | ||
echo 'echo "$CRON_SCHEDULE root /app/cron_job.sh" > /etc/cron.d/starwarden-cron' >> /app/start.sh && \ | ||
echo 'chmod 0644 /etc/cron.d/starwarden-cron' >> /app/start.sh && \ | ||
echo 'crontab /etc/cron.d/starwarden-cron' >> /app/start.sh && \ | ||
echo 'cron' >> /app/start.sh && \ | ||
echo 'if [ -n "$COLLECTION_ID" ]; then' >> /app/start.sh && \ | ||
echo ' /usr/local/bin/python /app/starwarden.py -id "$COLLECTION_ID"' >> /app/start.sh && \ | ||
echo 'else' >> /app/start.sh && \ | ||
echo ' echo "Error: COLLECTION_ID is not set"' >> /app/start.sh && \ | ||
echo 'fi' >> /app/start.sh && \ | ||
echo 'tail -f /app/starwarden.log' >> /app/start.sh && \ | ||
chmod +x /app/start.sh | ||
|
||
CMD ["/bin/sh", "-c", "/app/start.sh"] |
This file contains 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [year] [fullname] | ||
|
||
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. |
This file contains 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,15 @@ | ||
|
||
version: '3' | ||
|
||
services: | ||
starwarden: | ||
build: . | ||
environment: | ||
- GITHUB_TOKEN=${GITHUB_TOKEN} | ||
- GITHUB_USERNAME=${GITHUB_USERNAME} | ||
- LINKWARDEN_URL=${LINKWARDEN_URL} | ||
- LINKWARDEN_TOKEN=${LINKWARDEN_TOKEN} | ||
- COLLECTION_ID=${COLLECTION_ID} | ||
- CRON_SCHEDULE=${CRON_SCHEDULE:-0 0 * * *} | ||
volumes: | ||
- ./starwarden.log:/app/starwarden.log |
This file contains 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,15 @@ | ||
version: '3' | ||
|
||
services: | ||
starwarden: | ||
image: rtuszik/starwarden | ||
# env_file: .env ### for use with env file | ||
environment: | ||
- GITHUB_TOKEN=${GITHUB_TOKEN} | ||
- GITHUB_USERNAME=${GITHUB_USERNAME} | ||
- LINKWARDEN_URL=${LINKWARDEN_URL} | ||
- LINKWARDEN_TOKEN=${LINKWARDEN_TOKEN} | ||
- COLLECTION_ID=${COLLECTION_ID} | ||
- CRON_SCHEDULE=${CRON_SCHEDULE:-0 0 * * *} | ||
volumes: | ||
- ./starwarden.log:/app/starwarden.log |
Oops, something went wrong.