Skip to content

Commit

Permalink
actions: clean up docker builds; add standalone python build & test
Browse files Browse the repository at this point in the history
  • Loading branch information
mik3y committed May 1, 2020
1 parent f058a75 commit 3bf30e2
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 100 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/docker-amd64.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Build (amd64)

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
-
name: Available platforms
run: echo ${{ steps.build.outputs.platforms }}
-
name: Build
run: |
docker buildx build \
--platform linux/amd64 \
-t current \
--load .
-
name: Login to DockerHub Registry
if: success() && github.ref == 'refs/heads/master'
run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
-
name: Tag as latest
if: success() && github.ref == 'refs/heads/master'
run: |
docker tag current kegbot/server:latest
-
name: Publish
if: success() && github.ref == 'refs/heads/master'
run: |
docker push kegbot/server:latest
47 changes: 47 additions & 0 deletions .github/workflows/docker-arm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Build (armv7)

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Set up Docker Buildx
id: buildx
uses: crazy-max/ghaction-docker-buildx@v1
with:
version: latest
-
name: Available platforms
run: echo ${{ steps.build.outputs.platforms }}
-
name: Build
run: |
docker buildx build \
--platform linux/arm/v7 \
-t current \
--load .
-
name: Login to DockerHub Registry
if: success() && github.ref == 'refs/heads/master'
run: echo ${{ secrets.DOCKER_HUB_PASSWORD }} | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
-
name: Tag as latest-arm
if: success() && github.ref == 'refs/heads/master'
run: |
docker tag current kegbot/server:latest-arm
-
name: Publish
if: success() && github.ref == 'refs/heads/master'
run: |
docker push kegbot/server:latest-arm
33 changes: 0 additions & 33 deletions .github/workflows/dockerbuildx.yml

This file was deleted.

11 changes: 0 additions & 11 deletions .github/workflows/dockerimage.yml

This file was deleted.

55 changes: 0 additions & 55 deletions .github/workflows/dockerpublish.yml

This file was deleted.

33 changes: 33 additions & 0 deletions .github/workflows/pybuild.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Python Build & Test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Setup Python
uses: actions/setup-python@v1
with:
python-version: 3.7

- name: Install dependencies
run: |
pip install pipenv docker-compose
pipenv install --deploy --dev
- name: Run mysql & redis
run: |
docker-compose -f testdata/test-docker-compose.tml up -d
sleep 10 && ./bin/wait-for-container.sh testdata_mysql_1
- name: pytest
run: KEGBOT_DATABASE_URL=mysql://kegbot_dev:changeme@localhost:3306/kegbot_dev pipenv run pytest
28 changes: 28 additions & 0 deletions bin/wait-for-container.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

MAX_ATTEMPTS=60

function getContainerHealth {
docker inspect --format "{{.State.Health.Status}}" $1
}

function waitContainer {
attempts=0
while STATUS=$(getContainerHealth $1); [ $STATUS != "healthy" ]; do
if [ $STATUS == "unhealthy" ]; then
echo "container is unhealthy"
exit -1
fi
echo "container $1: status $STATUS ..."
lf=$'\n'
attempts=$[$attempts+1]
if [ $attempts -ge $MAX_ATTEMPTS ]; then
echo "Max attempts reached; fail"
exit -1
fi
sleep 1
done
echo "Container is up!"
}

waitContainer $1
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ services:
MYSQL_USER: 'kegbot_dev'
MYSQL_PASSWORD: 'changeme'
MYSQL_DATABASE: 'kegbot_dev'
healthcheck:
test: ["CMD", "mysqladmin", "ping", "--silent"]
interval: 10s
timeout: 10s
retries: 3
volumes:
- mysql-data:/var/lib/mysql

Expand Down
2 changes: 1 addition & 1 deletion pykeg/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,5 @@ def is_setup():
Setting("KEGBOT_IN_DOCKER", False, typefn=boolstr)
Setting("KEGBOT_SECRET_KEY", "not-configured")
Setting("KEGBOT_SETUP_ENABLED", False, typefn=boolstr)
Setting("KEGBOT_DATABASE_URL", os.getenv("DATABASE_URL", "mysql://root@localhost/kegbot"))
Setting("KEGBOT_DATABASE_URL", os.getenv("DATABASE_URL", "mysql://root@localhost:3306/kegbot"))
Setting("KEGBOT_REDIS_URL", os.getenv("REDIS_URL", "redis://localhost:6379/0"))
30 changes: 30 additions & 0 deletions testdata/test-docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# docker-compose for use in continuous integration
# Not for production!

version: '3'
services:
mysql:
image: mysql:latest
restart: always
environment:
MYSQL_ROOT_PASSWORD: 'changeme'
MYSQL_USER: 'kegbot_dev'
MYSQL_PASSWORD: 'changeme'
MYSQL_DATABASE: 'kegbot_dev'
healthcheck:
test: ["CMD", "mysqladmin", "ping", "--silent"]
interval: 10s
timeout: 10s
retries: 3
volumes:
- mysql-data:/var/lib/mysql
ports:
- "3306:3306"

redis:
image: redis:latest
restart: always

volumes:
mysql-data:
kegbot-data:

0 comments on commit 3bf30e2

Please sign in to comment.