From d6ebe0f0e512a4e3afbb9925fc93f062ed5ba646 Mon Sep 17 00:00:00 2001 From: Xander Bazzi Date: Thu, 6 Feb 2025 00:40:08 -0500 Subject: [PATCH] Dockerize the build process Add docker build commands to README Clean up Dockerfile.runtime --- .gitea/workflows/build-demo.yaml.disabled | 19 ++++++ .gitea/workflows/build-oci.yaml | 47 ++++++++++++++ Dockerfile.builder | 78 +++++++++++++++++++++++ Dockerfile.runtime | 17 +++++ README.md | 7 +- 5 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 .gitea/workflows/build-demo.yaml.disabled create mode 100644 .gitea/workflows/build-oci.yaml create mode 100644 Dockerfile.builder create mode 100644 Dockerfile.runtime diff --git a/.gitea/workflows/build-demo.yaml.disabled b/.gitea/workflows/build-demo.yaml.disabled new file mode 100644 index 0000000..394c807 --- /dev/null +++ b/.gitea/workflows/build-demo.yaml.disabled @@ -0,0 +1,19 @@ +name: Gitea Actions Demo +run-name: ${{ gitea.actor }} is testing out Gitea Actions 🚀 +on: [push] + +jobs: + Explore-Gitea-Actions: + runs-on: ubuntu-latest + steps: + - run: echo "🎉 The job was automatically triggered by a ${{ gitea.event_name }} event." + - run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by Gitea!" + - run: echo "🔎 The name of your branch is ${{ gitea.ref }} and your repository is ${{ gitea.repository }}." + - name: Check out repository code + uses: actions/checkout@v4 + - run: echo "💡 The ${{ gitea.repository }} repository has been cloned to the runner." + - run: echo "🖥️ The workflow is now ready to test your code on the runner." + - name: List files in the repository + run: | + ls ${{ gitea.workspace }} + - run: echo "🍏 This job's status is ${{ job.status }}." \ No newline at end of file diff --git a/.gitea/workflows/build-oci.yaml b/.gitea/workflows/build-oci.yaml new file mode 100644 index 0000000..678a3a4 --- /dev/null +++ b/.gitea/workflows/build-oci.yaml @@ -0,0 +1,47 @@ +name: Container Build & Push + +# add on pull requests too +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + container: + image: catthehacker/ubuntu:act-latest + env: + REGISTRY: www.gitgud.foo + OWNER: thegrind + TAG: 1.0.0 + IMAGE_NAME: test + steps: + - + name: Check out code + uses: actions/checkout@v3 + - name: whereami + run: ls -lath + + - + name: get dicks space + run: | + df -h + + - + name: Log in to the GitGud container registry + run: | + /usr/bin/docker login $REGISTRY \ + -u "${{ gitea.actor }}" \ + -p "${{ secrets.REGISTRY_PASSWORD }}" + + - + name: Build and push OCI image + run: | + IMAGE=$REGISTRY/$OWNER/$IMAGE_NAME:$TAG + docker build -t $IMAGE . + - + name: Push OCI image + run: | + IMAGE=$REGISTRY/$OWNER/$IMAGE_NAME:$TAG + docker push $IMAGE \ No newline at end of file diff --git a/Dockerfile.builder b/Dockerfile.builder new file mode 100644 index 0000000..49a6862 --- /dev/null +++ b/Dockerfile.builder @@ -0,0 +1,78 @@ +# Use the official golang:1.22.12-bookworm image as the build stage +FROM golang:1.22.12-bookworm + +# Create a directory /app +RUN mkdir /app + +# Set the working directory to /app +WORKDIR /app + +# Copy the current directory contents into /app +COPY ./ /app/ + +# Update the package list and install necessary packages +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + wget \ + vim \ + git \ + debconf \ + ca-certificates \ + tar \ + autoconf \ + automake \ + build-essential \ + cmake \ + git-core \ + libass-dev \ + libfreetype6-dev \ + libgnutls28-dev \ + libmp3lame-dev \ + libsdl2-dev \ + libtool \ + libva-dev \ + libvdpau-dev \ + libvorbis-dev \ + libxcb1-dev \ + libxcb-shm0-dev \ + libxcb-xfixes0-dev \ + meson \ + ninja-build \ + pkg-config \ + texinfo \ + yasm \ + zlib1g-dev \ + libx264-dev \ + libx265-dev \ + libnuma-dev \ + libvpx-dev \ + libopus-dev \ + libunistring-dev \ + libaom-dev \ + libdav1d-dev && \ + # Download Go module dependencies + go mod download && \ + # Download yt-dlp + wget --no-check-certificate -c https://github.com/yt-dlp/yt-dlp/releases/download/2025.01.26/yt-dlp_linux &&\ + # Download ffmpeg + wget --no-check-certificate -c https://www.johnvansickle.com/ffmpeg/old-releases/ffmpeg-6.0.1-amd64-static.tar.xz &&\ + # Move yt-dlp to /usr/bin and set permissions + mv yt-dlp_linux /usr/bin/yt-dlp && \ + chmod 755 /usr/bin/yt-dlp && \ + chmod +x /usr/bin/yt-dlp && \ + # Extract ffmpeg tarball + tar -xf ffmpeg-6.0.1-amd64-static.tar.xz && \ + # Remove the tarball + rm -rf ffmpeg-6.0.1-amd64-static.tar.xz && \ + # Set execute permissions for ffmpeg and ffprobe + chmod +x ffmpeg-6.0.1-amd64-static/ffmpeg && \ + chmod +x ffmpeg-6.0.1-amd64-static/ffprobe && \ + # Copy ffmpeg and ffprobe to /usr/bin + cp -R ffmpeg-6.0.1-amd64-static/ffmpeg /usr/bin/ && \ + cp -R ffmpeg-6.0.1-amd64-static/ffprobe /usr/bin/ && \ + # Remove the extracted ffmpeg directory + rm -rf ffmpeg-6.0.1-amd64-static && \ + # Create a new user 'papibot' + useradd papibot && \ + # Build the Go application + CGO_ENABLED=0 GOOS=linux go build -o /app/papibot diff --git a/Dockerfile.runtime b/Dockerfile.runtime new file mode 100644 index 0000000..8e66b82 --- /dev/null +++ b/Dockerfile.runtime @@ -0,0 +1,17 @@ +FROM www.gitgud.foo/thegrind/papibot-builder:latest as build + +# Create a group and user 'papibot' +RUN groupadd -r papibot && useradd -r -g papibot papibot + +# Switch to the 'papibot' user +USER papibot + +# Copy the necessary files from the build stage +COPY --from=build --chown=papibot:papibot /usr/bin/ /usr/bin +COPY --from=build --chown=papibot:papibot /app/ /app/ + +# Set the working directory to /app +WORKDIR /app/ + +# Set the entry point to the built Go application +ENTRYPOINT ["./papibot"] \ No newline at end of file diff --git a/README.md b/README.md index b14e760..41d02f1 100644 --- a/README.md +++ b/README.md @@ -19,4 +19,9 @@ Populate the discord bot keys `go run .` -type `!` in any channel in the discord while you're in a voice channel. \ No newline at end of file +type `!` in any channel in the discord while you're in a voice channel. + +## Build new builder container image +``` +docker build -t www.gitgud.foo/thegrind/papibot-builder: Dockerfile.builder +```