-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Ableytner/containerize
Build the bot as a docker image
- Loading branch information
Showing
15 changed files
with
226 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: Build image | ||
|
||
on: | ||
workflow_call: | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
build: | ||
runs-on: [self-hosted, linux] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
- name: lowercase github.repository | ||
run: | | ||
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | ||
- name: Build | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: false | ||
tags: ${{ env.IMAGE_NAME }}:latest | ||
outputs: type=docker,dest=/tmp/image.tar | ||
- name: Upload image artifact | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: image | ||
path: /tmp/image.tar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
name: Define Pylint | ||
|
||
on: | ||
workflow_call: | ||
inputs: | ||
python-version: | ||
required: true | ||
type: string | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
pylint: | ||
runs-on: | ||
- ${{ matrix.os }} | ||
- self-hosted | ||
strategy: | ||
matrix: | ||
os: [Linux] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ inputs.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ inputs.python-version }} | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install pylint | ||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | ||
- name: Analysing the code with pylint | ||
run: | | ||
pylint $(git ls-files '*.py') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
name: Release tagged image | ||
|
||
on: [workflow_dispatch] | ||
|
||
env: | ||
CURRENT_VERSION: 0.0.5 | ||
|
||
defaults: | ||
run: | ||
shell: bash | ||
|
||
jobs: | ||
pylint: | ||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.11", "3.12", "3.13"] | ||
uses: ./.github/workflows/define-pylint.yml | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
secrets: inherit | ||
|
||
build: | ||
needs: [pylint] | ||
uses: ./.github/workflows/define-build-image.yml | ||
secrets: inherit | ||
|
||
tag: | ||
runs-on: self-hosted | ||
steps: | ||
- uses: mukunku/[email protected] | ||
id: check-tag | ||
with: | ||
tag: ${{ env.CURRENT_VERSION }} | ||
- name: Fail if tag exists | ||
if: steps.check-tag.outputs.exists == 'true' | ||
run: | | ||
echo "Tag ${{ env.CURRENT_VERSION }} exists!" | ||
exit 1 | ||
- name: Print tag if it doesn't exist | ||
if: steps.check-tag.outputs.exists == 'false' | ||
run: | | ||
echo "Tag ${{ env.CURRENT_VERSION }} doesn't yet exist and can be created" | ||
push: | ||
needs: [tag, build] | ||
runs-on: [self-hosted, linux] | ||
permissions: | ||
contents: read | ||
packages: write | ||
steps: | ||
- name: Login to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: lowercase github.repository | ||
run: | | ||
echo "IMAGE_NAME=`echo ${{github.repository}} | tr '[:upper:]' '[:lower:]'`" >>${GITHUB_ENV} | ||
- name: Download image artifact | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: image | ||
path: /tmp | ||
- name: Load image | ||
run: | | ||
docker load --input /tmp/image.tar | ||
- name: Push | ||
run: | | ||
docker tag ${{ env.IMAGE_NAME }}:latest ghcr.io/${{ env.IMAGE_NAME }}:${{ env.CURRENT_VERSION }} | ||
docker push ghcr.io/${{ env.IMAGE_NAME }}:${{ env.CURRENT_VERSION }} | ||
docker tag ghcr.io/${{ env.IMAGE_NAME }}:${{ env.CURRENT_VERSION }} ghcr.io/${{ env.IMAGE_NAME }}:latest | ||
docker push ghcr.io/${{ env.IMAGE_NAME }}:latest | ||
release: | ||
needs: [push] | ||
runs-on: [self-hosted, linux] | ||
permissions: | ||
contents: write | ||
steps: | ||
- name: Add body.md | ||
run: | | ||
touch body.md | ||
- name: Create new release | ||
uses: ncipollo/release-action@v1 | ||
with: | ||
bodyFile: "body.md" | ||
tag: "${{ env.CURRENT_VERSION }}" | ||
commit: "main" | ||
token: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run Tests | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
pylint: | ||
strategy: | ||
matrix: | ||
python-version: ["3.10", "3.12"] | ||
uses: ./.github/workflows/define-pylint.yml | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
secrets: inherit | ||
build: | ||
needs: [pylint] | ||
uses: ./.github/workflows/define-build-image.yml | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:3.12-bookworm | ||
|
||
RUN apt-get update \ | ||
&& useradd -m nikobot \ | ||
&& mkdir /home/nikobot/src \ | ||
&& chown nikobot /home/nikobot/src | ||
|
||
COPY --chown=nikobot --chmod=755 src/ /home/nikobot/src/ | ||
COPY --chown=nikobot --chmod=755 requirements.txt /home/nikobot/requirements.txt | ||
|
||
# install pip packages | ||
RUN pip install -r /home/nikobot/requirements.txt | ||
|
||
USER nikobot | ||
|
||
ENTRYPOINT [ "python3", "/home/nikobot/src/main.py" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# pylint: skip-file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# pylint: skip-file | ||
|
||
from src.modules.tc4 import AspectParser | ||
|
||
def test_create(): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters