Skip to content

Commit

Permalink
Merge pull request #1 from MiraiSubject/add-docker-image-automation
Browse files Browse the repository at this point in the history
Add docker image (& automation)
  • Loading branch information
xdFNLeaks authored Jan 14, 2024
2 parents 3c75575 + 89a1197 commit e35ce05
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 1 deletion.
59 changes: 59 additions & 0 deletions .github/workflows/publish-image.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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" ]
2 changes: 1 addition & 1 deletion bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
12 changes: 12 additions & 0 deletions compose.build.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.

0 comments on commit e35ce05

Please sign in to comment.