Skip to content

Commit

Permalink
Implement CI for MystBin (#40)
Browse files Browse the repository at this point in the history
* first run at ci

* typo
  • Loading branch information
AbstractUmbra authored May 16, 2024
1 parent 5e3313f commit 6358119
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 5 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/build_and_push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.

name: Create and publish a Docker image

on:
workflow_dispatch:
push:
branches:
- main

concurrency:
cancel-in-progress: true
group: ci-${{ github.ref }}

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
env:
GIT_SHA: ${GITHUB_SHA::7}
permissions:
contents: read
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@master
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@master
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}

- name: Generate lowername image
id: image-name
run: |
echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >> "${GITHUB_OUTPUT}"
env:
IMAGE_NAME: '${{ env.IMAGE_NAME }}'

- name: Get short SHA
id: slug
run: echo "GIT_SHORT_SHA7=$(echo ${GITHUB_SHA} | cut -c1-7)" >> "$GITHUB_OUTPUT"

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ steps.meta.outputs.tags }}
ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME_LC }}:${{ steps.slug.outputs.GIT_SHORT_SHA7 }}
ghcr.io/${{ steps.image-name.outputs.IMAGE_NAME_LC }}:latest
labels: ${{ steps.meta.outputs.labels }}
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy

on:
workflow_run:
workflows: ["Create and publish a Docker image"]
branches: [main]
types:
- completed

jobs:
deploy:
name: Deploy bot
runs-on: ubuntu-latest
steps:
- name: Remote deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SSH_HOST }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
script: |
cd ~/mystbin
git reset --hard HEAD || true
git pull origin main
docker compose --profile redis pull
docker compose --profile redis up --build -d mystbin
username: ${{ secrets.SSH_USER }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.12-slim

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

RUN mkdir -p /etc/apt/keyrings \
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
services:
mystbin:
build:
context: .
dockerfile: Dockerfile
image: ghcr.io/pythonistaguild/mystbin
container_name: mystbin
ports:
- 8181:8181
Expand Down

0 comments on commit 6358119

Please sign in to comment.