Skip to content

Commit

Permalink
Merge pull request #16 from fykosak/dev-docker
Browse files Browse the repository at this point in the history
Move Astrid to docker
  • Loading branch information
Headary authored Jul 17, 2024
2 parents 07959a6 + 0f26856 commit f9ed867
Show file tree
Hide file tree
Showing 21 changed files with 357 additions and 175 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docker/*
!docker/entrypoint.sh
!docker/ssh.conf
!docker/sshd.conf
!docker/daemon.json
50 changes: 50 additions & 0 deletions .github/workflows/deploy-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Create and publish a Docker image

on:
push:
branchers:
- master
- dev-docker
paths:
- 'astrid/**'
- 'docker/**'
- 'main'
- 'requirements.txt'
- '.github/workflows/deploy-image.yml'

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

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
astrid.egg-info/
*~
*.pyc
docker/data
34 changes: 16 additions & 18 deletions astrid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,30 @@

class BuildLogger:
separator = ";"

def __init__(self, repodir):
self.repodir = repodir

def _getLogfile(self, reponame):
return os.path.expanduser('~/.astrid/{}.log'.format(reponame))
return f'/data/log/{reponame}.log'

def _getBuildlogfile(self, reponame):
return os.path.expanduser('~/.astrid/{}.build.log'.format(reponame))
def log(self, reponame, message, sendMail = False):
return f'/data/log/{reponame}.build.log'

def log(self, reponame, user, message, sendMail = False):
logfile = self._getLogfile(reponame)
f = open(logfile, "a")
user = cherrypy.request.login
f.write(BuildLogger.separator.join([datetime.now().isoformat(' '), message, user]) + "\n")
f.close()

if sendMail:
self._sendMail(reponame, message)

def getLogs(self, reponame):
logfile = self._getLogfile(reponame)
try:
f = open(logfile, "r")

records = [row.split(BuildLogger.separator) for row in reversed(list(f))]
f.close()
return records
Expand Down Expand Up @@ -68,8 +67,8 @@ def _sendMail(self, reponame, message):

from configparser import ConfigParser

REPOS_INI = '~/.astrid/repos.ini'
CONFIG_INI = '~/.astrid/config.ini'
REPOS_INI = '/data/config/repos.ini'
CONFIG_INI = '/data/config/config.ini'

repos = ConfigParser()
repos.read(os.path.expanduser(REPOS_INI))
Expand All @@ -80,14 +79,13 @@ def _sendMail(self, reponame, message):

# prepare locks for each repository
locks = {section: threading.Lock() for section in repos.sections()}
waitLocks = {section: threading.Lock() for section in repos.sections()}

from astrid.pages import BuilderPage, InfoPage, DashboardPage, BuildlogPage

repodir = cherrypy.config.get("repodir")

root = DashboardPage(repodir, repos, locks)
root.build = BuilderPage(repodir, repos, locks)
root.info = InfoPage(repodir, repos, locks)
root.buildlog = BuildlogPage(repodir, repos, locks)


root = DashboardPage(repodir, repos, locks, waitLocks)
root.build = BuilderPage(repodir, repos, locks, waitLocks)
root.info = InfoPage(repodir, repos, locks, waitLocks)
root.buildlog = BuildlogPage(repodir, repos, locks, waitLocks)
Loading

0 comments on commit f9ed867

Please sign in to comment.