Skip to content

Commit e489d85

Browse files
committed
Implement CI for Mystbin (#40)
* first run at ci
1 parent 5e3313f commit e489d85

File tree

4 files changed

+112
-5
lines changed

4 files changed

+112
-5
lines changed

.github/workflows/build_and_push.yaml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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+
workflow_dispatch:
14+
push:
15+
branches:
16+
- main
17+
18+
concurrency:
19+
cancel-in-progress: true
20+
group: ci-${{ github.ref }}
21+
22+
env:
23+
REGISTRY: ghcr.io
24+
IMAGE_NAME: ${{ github.repository }}
25+
26+
jobs:
27+
build-and-push-image:
28+
runs-on: ubuntu-latest
29+
env:
30+
GIT_SHA: ${GITHUB_SHA::7}
31+
permissions:
32+
contents: read
33+
packages: write
34+
35+
steps:
36+
- name: Checkout repository
37+
uses: actions/checkout@v4
38+
with:
39+
fetch-depth: 0
40+
41+
- name: Set up QEMU
42+
uses: docker/setup-qemu-action@v3
43+
44+
- name: Set up Docker Buildx
45+
uses: docker/setup-buildx-action@v3
46+
47+
- name: Log in to the Container registry
48+
uses: docker/login-action@master
49+
with:
50+
registry: ${{ env.REGISTRY }}
51+
username: ${{ github.actor }}
52+
password: ${{ secrets.GITHUB_TOKEN }}
53+
54+
- name: Extract metadata (tags, labels) for Docker
55+
id: meta
56+
uses: docker/metadata-action@master
57+
with:
58+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
59+
60+
- name: Generate lowername image
61+
id: image-name
62+
run: |
63+
echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >> "${GITHUB_OUTPUT}"
64+
env:
65+
IMAGE_NAME: '${{ env.IMAGE_NAME }}'
66+
67+
- name: Get short SHA
68+
id: slug
69+
run: echo "GIT_SHORT_SHA7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"
70+
71+
- name: Build and push Docker image
72+
uses: docker/build-push-action@v5
73+
with:
74+
context: .
75+
push: true
76+
tags: |
77+
${{ steps.meta.outputs.tags }}
78+
ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME_LC }}:${{ steps.slug.outputs.GIT_SHORT_SHA7 }}
79+
ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME_LC }}:latest
80+
labels: ${{ steps.meta.outputs.labels }}

.github/workflows/deploy.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Create and publish a Docker image"]
6+
branches: [main]
7+
types:
8+
- completed
9+
10+
jobs:
11+
deploy:
12+
name: Deploy bot
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Remote deploy
16+
uses: appleboy/ssh-action@master
17+
with:
18+
host: ${{ secrets.SSH_HOST }}
19+
key: ${{ secrets.SSH_KEY }}
20+
port: ${{ secrets.SSH_PORT }}
21+
script: |
22+
cd ~/mystbin
23+
git reset --hard HEAD || true
24+
git pull origin main
25+
docker compose --profile redis pull
26+
docker compose --profile redis up --build -d mystbin
27+
username: ${{ secrets.SSH_USER }}

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM python:3.12-slim
22

3-
LABEL org.opencontainers.image.source=https://github.com/pythonistaguild/mystbin-backend
4-
LABEL org.opencontainers.image.description="Mystbin's Python Backend"
3+
LABEL org.opencontainers.image.source=https://github.com/pythonistaguild/mystbin
4+
LABEL org.opencontainers.image.description="Container for running MystB.in"
55
LABEL org.opencontainers.image.licenses=GPLv3
66

77
RUN mkdir -p /etc/apt/keyrings \

docker-compose.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
services:
22
mystbin:
3-
build:
4-
context: .
5-
dockerfile: Dockerfile
3+
image: ghcr.io/pythonistaguild/mystbin
64
container_name: mystbin
75
ports:
86
- 8181:8181
@@ -11,6 +9,8 @@ services:
119
database:
1210
condition: service_healthy
1311
restart: true
12+
volumes:
13+
- ./config.toml:/app/config.toml:ro
1414

1515
database:
1616
image: postgres:latest

0 commit comments

Comments
 (0)