Skip to content

Commit 7b37405

Browse files
Change build process for Docker images (#40)
* add image building capability * allow actions to deploy the image * remove unneeded steps
1 parent df14081 commit 7b37405

File tree

5 files changed

+90
-11
lines changed

5 files changed

+90
-11
lines changed

Diff for: .dockerignore

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
__pycache__/
2+
*.py[cod]
3+
_pyright/
4+
.git/
5+
.github/
6+
.venv/
7+
.vscode/
8+
.idea/
9+
logs/
10+
.gitignore
11+
.gitmodules
12+
**/*.ipynb
13+
docker-compose.yml
14+
Dockerfile
15+
LICENSE
16+
README.md
17+
requirements.txt
18+
dev-requirements.txt
19+
config.template.toml
20+
.template.env

Diff for: .github/workflows/build_and_push.yaml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Create and publish a Docker image
11+
12+
on:
13+
push:
14+
branches:
15+
- main
16+
17+
concurrency:
18+
cancel-in-progress: true
19+
group: ci-${{ github.ref }}
20+
21+
env:
22+
REGISTRY: ghcr.io
23+
IMAGE_NAME: ${{ github.repository }}
24+
25+
jobs:
26+
build-and-push-image:
27+
runs-on: ubuntu-latest
28+
permissions:
29+
contents: read
30+
packages: write
31+
32+
steps:
33+
- name: Checkout repository
34+
uses: actions/checkout@v3
35+
36+
- name: Log in to the Container registry
37+
uses: docker/login-action@master
38+
with:
39+
registry: ${{ env.REGISTRY }}
40+
username: ${{ github.actor }}
41+
password: ${{ secrets.GITHUB_TOKEN }}
42+
43+
- name: Extract metadata (tags, labels) for Docker
44+
id: meta
45+
uses: docker/metadata-action@master
46+
with:
47+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
48+
49+
- name: Build and push Docker image
50+
uses: docker/build-push-action@master
51+
with:
52+
context: .
53+
push: true
54+
tags: "ghcr.io/pythonistaguild/pythonista-bot:latest"
55+
labels: ${{ steps.meta.outputs.labels }}

Diff for: .github/workflows/deploy.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ jobs:
1010
key: ${{ secrets.SSH_KEY }}
1111
port: ${{ secrets.SSH_PORT }}
1212
script: |
13-
cd ~/projects/pythonista-bot/
14-
git stash || true
15-
git pull --force || true
13+
docker compose pull bot
1614
docker compose up --build -d
1715
username: ${{ secrets.SSH_USER }}
1816

1917
name: Deploy
2018

2119
on:
22-
push:
23-
branches:
24-
- main
20+
workflow_run:
21+
workflows: ["Create and publish a Docker image"]
22+
branches: [main]
23+
types:
24+
- completed

Diff for: Dockerfile

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
FROM python:3.11-slim
22

3+
LABEL org.opencontainers.image.source=https://github.com/PythonistaGuild/Pythonista-Bot
4+
LABEL org.opencontainers.image.description="Pythonista Guild's Discord Bot"
5+
LABEL org.opencontainers.image.licenses=MIT
6+
37
ENV PYTHONUNBUFFERED=1 \
48
# prevents python creating .pyc files
59
PYTHONDONTWRITEBYTECODE=1 \
@@ -44,7 +48,7 @@ WORKDIR /app
4448
COPY poetry.lock pyproject.toml ./
4549

4650
# install runtime deps - uses $POETRY_VIRTUALENVS_IN_PROJECT internally
47-
RUN poetry install --without=dev
51+
RUN poetry install --only=main
4852

4953
COPY . /app/
5054
ENTRYPOINT poetry run python -O launcher.py

Diff for: docker-compose.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
services:
22
bot:
3-
build:
4-
context: .
5-
dockerfile: Dockerfile
63
container_name: pythonista-bot
74
depends_on:
85
- database
9-
restart: always
6+
image: ghcr.io/pythonistaguild/pythonista-bot:latest
7+
restart: unless-stopped
8+
volumes:
9+
- ./config.toml:/app/config.toml:ro
1010

1111
database:
1212
container_name: pythonista-bot-db

0 commit comments

Comments
 (0)