Skip to content

Commit

Permalink
Setup Github Actions (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
coilysiren authored Nov 19, 2023
1 parent 8cdab10 commit 70ee3dc
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
14 changes: 8 additions & 6 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
name: Docker Image CI
name: CI/CD

on:
push:
branches: ["main"]
branches:
- main
pull_request:
branches: ["main"]
branches:
- main

jobs:
test:
runs-on: ubuntu-latest
container:
image: python:3.11
steps:
- uses: actions/checkout@v3
- run: pip install invoke
- run: make pyenv-ubuntu
- run: echo "$HOME/.pyenv/bin:$PATH" >> $GITHUB_PATH
- run: make install
- run: invoke test
17 changes: 9 additions & 8 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
help: ## Show this help.
@egrep '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'

ifdef CI
python: # python should already be installed in CI
python --version
else
python: # install python
pyenv install --skip-existing
endif
pyenv-ubuntu: ## install pyenv on ubuntu
sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev \
liblzma-dev
curl https://pyenv.run | bash

install: ## install python, and python packages
$(MAKE) python
echo $(PATH)
pyenv install --skip-existing
pip install invoke pyyaml
python -m venv venv
./venv/bin/pip install --upgrade pip pipenv
./venv/bin/pip install -r src/requirements-dev.txt
Expand Down
15 changes: 6 additions & 9 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ def build(ctx: [invoke.Context, Context]):
# get local configurations
ctx = Context(ctx)

# generate requirements.txt
ctx.run("pipenv requirements > requirements.txt")

# build docker image
ctx.run(f"docker build --tag {ctx.name}:{ctx.version} . --target base", pty=True)
ctx.run(f"BUILDKIT_PROGRESS=plain docker build --tag {ctx.name}:{ctx.version} . --target base", pty=True)


@invoke.task
Expand Down Expand Up @@ -141,28 +138,28 @@ def deploy(ctx: [invoke.Context, Context]):
@invoke.task
def serve(ctx: [invoke.Context, Context]):
"""serve up the application, so that it can be accessed locally"""
ctx.run("docker compose up --build flask", pty=True)
ctx.run("BUILDKIT_PROGRESS=plain docker compose up --build flask", pty=True)


@invoke.task
def test(ctx: [invoke.Context, Context]):
"""run tests"""
ctx.run("docker compose run --build pytest", pty=True)
ctx.run("BUILDKIT_PROGRESS=plain docker compose run --build pytest", pty=True)


@invoke.task
def test_watch(ctx: [invoke.Context, Context]):
"""run tests in watch mode"""
ctx.run("docker compose run --build ptw", pty=True)
ctx.run("BUILDKIT_PROGRESS=plain docker compose run --build ptw", pty=True)


@invoke.task
def migration_create(ctx: [invoke.Context, Context]):
"""create a new database migration"""
ctx.run("docker compose run --build create-migration", pty=True)
ctx.run("BUILDKIT_PROGRESS=plain docker compose run --build create-migration", pty=True)


@invoke.task
def migration_run_locally(ctx: [invoke.Context, Context]):
"""run a local database migration"""
ctx.run("docker compose run --build run-local-migration", pty=True)
ctx.run("BUILDKIT_PROGRESS=plain docker compose run --build run-local-migration", pty=True)

0 comments on commit 70ee3dc

Please sign in to comment.