Skip to content

Commit

Permalink
Docker automation
Browse files Browse the repository at this point in the history
  • Loading branch information
westsurname authored May 15, 2024
1 parent 4d373b2 commit e3e7d0a
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TRAKT_API_KEY=<trakt_api_key>

WATCHLIST_PLEX_PRODUCT="Plex Request Authentication"
WATCHLIST_PLEX_VERSION="1.0.0"
WATCHLIST_PLEX_CLIENT_IDENTIFIER="4e5a6f40-a7bd-4f4a-9c4e-bf242e7c70b1"
WATCHLIST_PLEX_CLIENT_IDENTIFIER="576101fc-b425-4685-91cb-5d3c1671fd2b"

BLACKHOLE_RD_MOUNT_TORRENTS_PATH=<blackhole_rd_mount_torrents_path>
BLACKHOLE_BASE_WATCH_PATH="./blackhole"
Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Build and Push Docker images

on:
push:
branches:
- main

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

- name: Log in to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - name: Load .env file
# id: dotenv
# uses: falti/[email protected]

- name: Build and push blackhole image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.blackhole
push: true
tags: ghcr.io/${{ github.repository }}/blackhole:latest

- name: Build and push watchlist image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.watchlist
push: true
tags: ghcr.io/${{ github.repository }}/watchlist:latest

- name: Build and push plex_authentication image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.plex_authentication
push: true
tags: ghcr.io/${{ github.repository }}/plex_authentication:latest

- name: Build and push plex_request image
uses: docker/build-push-action@v2
with:
context: .
file: ./Dockerfile.plex_request
push: true
tags: ghcr.io/${{ github.repository }}/plex_request:latest

14 changes: 11 additions & 3 deletions Dockerfile.blackhole
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
FROM python:3.8-slim

# Metadata labels
LABEL org.opencontainers.image.source="https://github.com/westsurname/scripts"
LABEL org.opencontainers.image.description="Docker image for the blackhole service"

ARG SERVICE_NAME=blackhole

# Set working directory
WORKDIR /app

COPY . .
# Copy only the files needed for pip install to maximize cache utilization
COPY requirements.txt ./

# Install Python dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt
RUN pip install --no-cache-dir -r service_requirements.txt
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt && \
pip install --no-cache-dir -r service_requirements.txt

# Copy the rest of the application
COPY . .

CMD ["python", "blackhole_watcher.py"]
18 changes: 12 additions & 6 deletions Dockerfile.plex_authentication
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
FROM python:3.8-slim

# Metadata labels
LABEL org.opencontainers.image.source="https://github.com/westsurname/scripts"
LABEL org.opencontainers.image.description="Docker image for the plex_authentication service"

ARG SERVICE_NAME=plex_authentication

# Set working directory
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . .
# Copy only the files needed for pip install to maximize cache utilization
COPY requirements.txt ./

# Install gunicorn and other dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt
RUN pip install --no-cache-dir gunicorn -r service_requirements.txt
# Install Python dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt && \
pip install --no-cache-dir -r service_requirements.txt

# Copy the rest of the application
COPY . .

# Expose port 8000 to the outside world
EXPOSE 8000

# Run gunicorn on port 8000, add more workers if required
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "plex_authentication_wsgi:app"]

18 changes: 12 additions & 6 deletions Dockerfile.plex_request
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
FROM python:3.8-slim

# Metadata labels
LABEL org.opencontainers.image.source="https://github.com/westsurname/scripts"
LABEL org.opencontainers.image.description="Docker image for the plex_request service"

ARG SERVICE_NAME=plex_request

# Set working directory
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . .
# Copy only the files needed for pip install to maximize cache utilization
COPY requirements.txt ./

# Install gunicorn and other dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt
RUN pip install --no-cache-dir gunicorn -r service_requirements.txt
# Install Python dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt && \
pip install --no-cache-dir -r service_requirements.txt

# Copy the rest of the application
COPY . .

# Expose port 8000 to the outside world
EXPOSE 8000

# Run gunicorn on port 8000, add more workers if required
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "plex_request_wsgi:app"]

14 changes: 11 additions & 3 deletions Dockerfile.watchlist
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
FROM python:3.8-slim

# Metadata labels
LABEL org.opencontainers.image.source="https://github.com/westsurname/scripts"
LABEL org.opencontainers.image.description="Docker image for the watchlist service"

ARG SERVICE_NAME=watchlist

# Set working directory
WORKDIR /app

COPY . .
# Copy only the files needed for pip install to maximize cache utilization
COPY requirements.txt ./

# Install Python dependencies
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt
RUN pip install --no-cache-dir -r service_requirements.txt
RUN grep -E "#.*($SERVICE_NAME|all)" requirements.txt | awk '{print $0}' > service_requirements.txt && \
pip install --no-cache-dir -r service_requirements.txt

# Copy the rest of the application
COPY . .

CMD ["python", "watchlist_runner.py"]
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ x-blackhole: &blackhole
build:
context: .
dockerfile: Dockerfile.blackhole
image: ghcr.io/westsurname/scripts/blackhole:latest
# user: "${PUID:-1000}:${PGID:-1000}"
env_file:
- .env
Expand All @@ -13,7 +14,6 @@ services:
blackhole:
<<: *blackhole
container_name: blackhole_service
image: blackhole
environment:
- BLACKHOLE_BASE_WATCH_PATH=/${BLACKHOLE_BASE_WATCH_PATH}
volumes:
Expand All @@ -25,7 +25,6 @@ services:
blackhole_4k:
<<: *blackhole
container_name: blackhole_4k_service
image: blackhole_4k
environment:
- SONARR_HOST=${SONARR_HOST_4K}
- SONARR_API_KEY=${SONARR_API_KEY_4K}
Expand All @@ -43,7 +42,7 @@ services:
context: .
dockerfile: Dockerfile.watchlist
container_name: watchlist_service
image: watchlist
image: ghcr.io/westsurname/scripts/watchlist:latest
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
env_file:
Expand All @@ -56,7 +55,7 @@ services:
context: .
dockerfile: Dockerfile.plex_authentication
container_name: plex_authentication_service
image: plex_authentication
image: ghcr.io/westsurname/scripts/plex_authentication:latest
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
ports:
Expand All @@ -73,7 +72,7 @@ services:
context: .
dockerfile: Dockerfile.plex_request
container_name: plex_request_service
image: plex_request
image: ghcr.io/westsurname/scripts/plex_request:latest
volumes:
- ./shared/tokens.json:/app/shared/tokens.json
ports:
Expand Down

0 comments on commit e3e7d0a

Please sign in to comment.