-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat: Update Docker and CI #2432
Changes from all commits
290df63
1510a4a
fd5c197
6b788c1
541476b
318e324
e6ca484
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
rules: | ||
lowestEfficiency: 0.97 # ratio between 0-1 | ||
highestWastedBytes: 20MB # B, KB, MB, and GB | ||
highestUserWastedPercent: 0.20 # ratio between 0-1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
COMPOSE_FILE=docker-compose.yml | ||
COMPOSE_REMOVE_ORPHANS=true | ||
# * Options: linux/amd64 / linux/arm64/v8 | ||
PLATFORM=linux/arm64/v8 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- 'main' | ||
- 'master' | ||
tags: | ||
- '*.*.*' | ||
paths: | ||
- 'Dockerfile*' | ||
- 'pyproject.toml' | ||
- 'poetry.lock' | ||
- 'requirements.txt' | ||
- '**.py' | ||
- '**.sh' | ||
- '.dockerignore' | ||
- '.env.example' | ||
- '.github/workflows/**' | ||
workflow_dispatch: | ||
|
||
env: | ||
REGISTRY_URL: ${{ vars.REGISTRY_URL }} | ||
REGISTRY_USER: ${{ vars.REGISTRY_USER }} | ||
|
||
jobs: | ||
build: | ||
name: Build and push Docker image | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: true | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set password by container registry | ||
run: | | ||
case "${{ env.REGISTRY_URL }}" in | ||
"ghcr.io") | ||
echo "REGISTRY_PASS=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV | ||
;; | ||
*) | ||
if [ -n "${{ secrets.REGISTRY_PASS }}" ]; then | ||
echo "REGISTRY_PASS=${{ secrets.REGISTRY_PASS }}" >> $GITHUB_ENV | ||
else | ||
echo "REGISTRY_PASS secret is not set and registry is not recognized. Exiting..." | ||
exit 1 | ||
fi | ||
;; | ||
esac | ||
- name: Log into container registry | ||
if: github.event_name != 'pull_request' | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.REGISTRY_URL }} | ||
username: ${{ env.REGISTRY_USER }} | ||
password: ${{ env.REGISTRY_PASS }} | ||
|
||
- name: Set image name | ||
id: image_name | ||
run: | | ||
if [ -n "${{ env.IMAGE }}" ]; then | ||
IMAGE="${{ env.IMAGE }}" | ||
else | ||
IMAGE=$(grep "LABEL org.opencontainers.image.title" Dockerfile | cut -d'"' -f2) | ||
fi | ||
echo "IMAGE=$IMAGE" >> $GITHUB_OUTPUT | ||
echo "IMAGE=$IMAGE" >> $GITHUB_ENV | ||
- name: Docker meta | ||
id: meta | ||
uses: docker/metadata-action@v5 | ||
with: | ||
images: | | ||
${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }} | ||
tags: | | ||
type=schedule | ||
type=ref,event=branch | ||
type=ref,event=pr | ||
type=semver,pattern={{version}} | ||
type=semver,pattern={{major}}.{{minor}} | ||
type=semver,pattern={{major}} | ||
type=sha | ||
type=raw,value=latest,enable={{is_default_branch}} | ||
- name: Setup QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Setup Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
platforms: linux/amd64,linux/arm64/v8 | ||
push: ${{ github.event_name != 'pull_request' }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
cache-from: type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache | ||
cache-to: type=registry,ref=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ steps.image_name.outputs.IMAGE }}:buildcache,mode=max | ||
Comment on lines
+36
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is all so insanely complex for a simple task such as uploading a built docker image to github's container registry. I built this exact workflow in another repo I maintain @ here, feel free to use it as inspiration as this workflow is really awful. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
failure-threshold: info # error|warning|info|style|ignore|none | ||
|
||
ignored: | ||
- DL3008 # pin versions in apt | ||
- DL3013 # pin versions in pip | ||
- DL3018 # pin versions in apk | ||
- DL3042 # pip --no-cache-dir | ||
|
||
trustedRegistries: | ||
- docker.io | ||
- "*.gcr.io" | ||
- localhost:32000 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
FROM python:3.8-alpine | ||
# syntax=docker/dockerfile:1.7.0 | ||
|
||
FROM python:3.8-alpine3.20 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reason to deeply specify the alpine version? |
||
|
||
# Add project source | ||
WORKDIR /musicbot | ||
|
@@ -7,22 +9,33 @@ COPY ./config sample_config | |
|
||
# Install build dependencies | ||
RUN apk update && apk add --no-cache --virtual .build-deps \ | ||
build-base \ | ||
libffi-dev \ | ||
libsodium-dev | ||
build-base \ | ||
libffi-dev \ | ||
libsodium-dev \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
# Install dependencies | ||
RUN apk update && apk add --no-cache \ | ||
ca-certificates \ | ||
ffmpeg \ | ||
opus-dev \ | ||
libffi \ | ||
libsodium \ | ||
gcc \ | ||
git | ||
ca-certificates \ | ||
ffmpeg \ | ||
gcc \ | ||
git \ | ||
libffi \ | ||
libsodium \ | ||
opus-dev \ | ||
&& rm -rf /var/cache/apk/* | ||
|
||
# pip env vars | ||
ENV PIP_NO_CACHE_DIR=off | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK=on | ||
ENV PIP_DEFAULT_TIMEOUT=100 | ||
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these aren't needed as well. No reason to add them |
||
|
||
# don't generate .pyc, enable tracebacks on seg faults | ||
ENV PYTHONDONTWRITEBYTECODE=1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we dont want this enabled. It greatly reduces performance |
||
ENV PYTHONFAULTHANDLER=1 | ||
|
||
# Install pip dependencies | ||
RUN pip3 install --no-cache-dir -r requirements.txt | ||
RUN python -m pip install --no-cache-dir -r requirements.txt | ||
|
||
# Clean up build dependencies | ||
RUN apk del .build-deps | ||
|
@@ -33,3 +46,5 @@ VOLUME ["/musicbot/audio_cache", "/musicbot/config", "/musicbot/data", "/musicbo | |
ENV APP_ENV=docker | ||
|
||
ENTRYPOINT ["/bin/sh", "docker-entrypoint.sh"] | ||
|
||
LABEL org.opencontainers.image.title="musicbot" |
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.
what will this actually do? this seems largely pointless and should just be removed