diff --git a/.github/workflows/publish-image.yml b/.github/workflows/publish-image.yml new file mode 100644 index 0000000..55c1ca6 --- /dev/null +++ b/.github/workflows/publish-image.yml @@ -0,0 +1,59 @@ +# Taken from: https://docs.github.com/en/actions/publishing-packages/publishing-docker-images +name: Create and publish a Docker image + +# Configures this workflow to run every time a change is pushed to the branch called `release`. +on: + release: + types: [published] + push: + branches: ["main"] + +# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. +jobs: + build-and-push-image: + runs-on: ubuntu-latest + # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v4 + # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. + - name: Log in to the Container registry + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. + # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository. + # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: | + ${{ steps.meta.outputs.labels }} + org.opencontainers.image.title=Managebot + org.opencontainers.image.description=just a little project i'm working on that allows you to view and manage your docker containers from discord. + org.opencontainers.image.vendor=xdFNLeaks diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..403fc7b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM python:3.11 as builder +RUN apt-get update -y && apt-get install -y ca-certificates curl gnupg +RUN install -m 0755 -d /etc/apt/keyrings +RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +RUN chmod a+r /etc/apt/keyrings/docker.gpg +RUN echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null +RUN apt-get update +RUN apt-get -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin + +FROM builder as pythonsetup +WORKDIR /usr/src/app +RUN pip install -U py-cord --pre + +FROM pythonsetup +WORKDIR /usr/src/app +COPY "bot.py" . +VOLUME [ "/var/run/docker.sock" ] +VOLUME [ "/usr/src/app/config" ] +CMD [ "python", "./bot.py" ] diff --git a/bot.py b/bot.py index 1b1f954..e210e29 100644 --- a/bot.py +++ b/bot.py @@ -7,7 +7,7 @@ bot = discord.Bot() -with open("config.json", "r") as config_file: +with open("config/config.json", "r") as config_file: config = json.load(config_file) def get_current_time(): diff --git a/compose.build.yaml b/compose.build.yaml new file mode 100644 index 0000000..7baccae --- /dev/null +++ b/compose.build.yaml @@ -0,0 +1,12 @@ +version: "3.3" +services: + managebot: + container_name: managebot + privileged: true + restart: unless-stopped + build: + context: . + dockerfile: Dockerfile + volumes: + - ./config:/usr/src/app/config + - /var/run/docker.sock:/var/run/docker.sock diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..5f8e2a3 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,10 @@ +version: "3.3" +services: + managebot: + container_name: managebot + privileged: true + restart: unless-stopped + image: "ghcr.io/xdFNLeaks/managebot:latest" + volumes: + - ./config:/usr/src/app/config + - /var/run/docker.sock:/var/run/docker.sock diff --git a/config.json b/config/config.json similarity index 100% rename from config.json rename to config/config.json