Skip to content

Commit

Permalink
Moving to GitHub actions (#483)
Browse files Browse the repository at this point in the history
* Checking?

* Fix.

* because yml.

* Add ci make target.

* Bye bye Poetry.

* More fixes.

* pip-tools

* Split actions.

* Node

* bye gitlab

* err?

* Use 3.7.

* Run tests directly.

* Lint, too.

* Black.

* Use flake8.

* Fx.

* Fix dotenv.

* Add isort config.

* Remove this again.

* Fix importsd.

* Try agin.

* Fix black/isort.

* Disable autobuilt.

* Sigh.

* Add webassets cache.

* Move to Parcel.

* Use wait-for-it.

* No whitenoise.
  • Loading branch information
jezdez authored Sep 19, 2019
1 parent 6b5dd7b commit 0673746
Show file tree
Hide file tree
Showing 64 changed files with 8,364 additions and 1,257 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Pull request
on:
pull_request:
branches:
- master

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
pip install flake8 flake8-black flake8-isort
- name: Run flake8
run: |
flake8 .
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Test
run: make ci
13 changes: 6 additions & 7 deletions .github/workflows/tests.yml → .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
name: CI
name: Push
on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
test:
name: Run tests
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: Test
run: make test
run: make ci

deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Push
if: github.event_name == 'push' && github.ref == refs/heads/master
uses: vitalyliber/dokku-github-action@master
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.env
jazzband/static/.webassets-cache
jazzband/static/css/styles.*.css
jazzband/static/dist
venv/
.eggs
*.egg-info
Expand Down
38 changes: 0 additions & 38 deletions .gitlab-ci.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .isort.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[settings]
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
27 changes: 11 additions & 16 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
FROM node as npm

COPY package.json package-lock.json /tmp/
COPY . /tmp/

WORKDIR /tmp

RUN npm install
RUN npm install \
&& npm run build

# -----------------------------------------------------------------------------

FROM python:3.6-stretch
FROM python:3.7

ARG POETRY_ARGS="--no-dev --no-interaction --no-ansi"

ENV POETRY_ARGS=${POETRY_ARGS} \
PYTHONPATH=/app/ \
ENV PYTHONPATH=/app/ \
PYTHONFAULTHANDLER=1 \
PYTHONUNBUFFERED=1 \
PYTHONHASHSEED=random \
PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
LANG=C.UTF-8 \
POETRY_VERSION=0.12.16 \
PATH=/app/.local/bin:$PATH
LANG=C.UTF-8

# add a non-privileged user for installing and running the application
# don't use --create-home option to prevent populating with skeleton files
Expand All @@ -42,23 +38,22 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential curl git libpq-dev \
postgresql-client gettext sqlite3 libffi-dev \
inotify-tools wget bzip2 && \
inotify-tools wget bzip2 wait-for-it && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN pip install -U pip && \
pip install "poetry==$POETRY_VERSION"
RUN pip install -U pip

WORKDIR /app
COPY poetry.lock pyproject.toml /app/
COPY requirements.txt /app/

RUN poetry config settings.virtualenvs.create false && \
poetry install $POETRY_ARGS
RUN pip install -r requirements.txt

COPY . /app/

COPY --from=npm /tmp/node_modules /app/node_modules/
COPY --from=npm /tmp/jazzband/static/dist /app/jazzband/static/dist/

RUN chown -R 10001:10001 /app

Expand Down
25 changes: 18 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
.PHONY: bash npm-install build clean db-migrate db-upgrade redis-cli run shell start stop update test
.PHONY: bash npm-build npm-install build clean db-migrate db-upgrade redis-cli run shell start stop update test pytest container-build envvar ci

bash:
docker-compose run --rm web bash

npm-install:
npm install

build: npm-install
docker-compose build --pull --build-arg POETRY_ARGS="--no-interaction --no-ansi"
npm-build:
npm run build

container-build:
docker-compose build --pull

build: npm-install npm-build container-build

clean: stop
docker-compose rm -f
find . -name "*.pyc" -delete
rm -rf jazzband/static/.webassets-cache
rm -rf jazzband/static/css/styles.*.css
rm -rf jazzband/static/dist

db-migrate:
docker-compose run --rm web flask db migrate
Expand All @@ -37,7 +41,14 @@ stop:
docker-compose stop

update:
docker-compose run --rm web poetry update
docker-compose run --rm web pip install -r requirements.txt

test: build
pytest:
docker-compose run --rm web pytest tests/

test: pytest

envvar:
cp .env-dist .env

ci: envvar test
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ under the MIT license.

[add-to-org]: https://github.com/benbalter/add-to-org
[Attribution-NonCommercial-ShareAlike 4.0 International]: https://creativecommons.org/licenses/by-nc-sa/4.0/

6 changes: 3 additions & 3 deletions tests/conftest.py → conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@pytest.fixture
def app():
app = create_app()
app.config['DEBUG'] = True
app.config['VALIDATE_IP'] = False
app.config['VALIDATE_SIGNATURE'] = False
app.config["DEBUG"] = True
app.config["VALIDATE_IP"] = False
app.config["VALIDATE_SIGNATURE"] = False
return app
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ services:
volumes:
- .:/app
- cache:/app/.cache:delegated
command: honcho start -f Procfile.dev web
command: sh -c 'wait-for-it db:5432 redis:6379 -- honcho start -f Procfile.dev' web
environment:
# pass those two into the environment
# but also response the .env file for the rest
FLASK_APP: jazzband/app.py
FLASK_DEBUG: 1
PORT: 5000
env_file:
- .env
ports:
Expand All @@ -34,7 +33,7 @@ services:

worker:
<<: *app
command: honcho start -f Procfile.dev worker
command: sh -c 'wait-for-it db:5432 redis:6379 -- honcho start -f Procfile.dev worker'
ports: []

volumes:
Expand Down
24 changes: 0 additions & 24 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,31 +1,7 @@
#!/usr/bin/env bash
set -eo pipefail

# default variables
: "${PORT:=5000}"
: "${SLEEP:=1}"
: "${TRIES:=60}"

function wait_for_check {(
tries=0
echo "Waiting for $1 to respond..."
while true; do
[[ $tries -lt $TRIES ]] || return
flask check $1 >/dev/null 2>&1
[[ $? -eq 0 ]] && return
sleep $SLEEP
tries=$((tries + 1))
done
)}

# first wait for the database
wait_for_check redis
wait_for_check db

# then run the database migrations
flask db upgrade

# then build the assets
flask assets build

exec "$@"
4 changes: 2 additions & 2 deletions jazzband/account/blueprint.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from flask import current_app, flash
from flask_login import current_user, login_user
from flask_dance.consumer import OAuth2ConsumerBlueprint, oauth_error
from flask_dance.consumer.requests import OAuth2Session, BaseOAuth2Session
from flask_dance.consumer.requests import BaseOAuth2Session, OAuth2Session
from flask_dance.consumer.storage.sqla import SQLAlchemyStorage
from flask_login import current_user, login_user
from sentry_sdk import capture_message, configure_scope
from urlobject import URLObject
from werkzeug.utils import cached_property
Expand Down
2 changes: 1 addition & 1 deletion jazzband/account/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask_login import current_user
from flask_wtf import FlaskForm
from wtforms import validators, ValidationError
from wtforms import ValidationError, validators
from wtforms.fields import BooleanField, StringField

CONSENT_ERROR_MESSAGE = "Your consent is required to continue."
Expand Down
7 changes: 3 additions & 4 deletions jazzband/account/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from datetime import datetime

import sentry_sdk
from flask import flash, redirect, request, session, url_for, Blueprint
from flask_login import current_user, login_user, logout_user, login_required
from flask_dance.consumer import oauth_before_login, oauth_authorized
from flask import Blueprint, flash, redirect, request, session, url_for
from flask_dance.consumer import oauth_authorized, oauth_before_login
from flask_login import current_user, login_required, login_user, logout_user
from sqlalchemy.orm.exc import NoResultFound

from ..db import postgres as db
Expand All @@ -14,7 +14,6 @@
from ..members.tasks import sync_email_addresses
from ..tasks import spinach
from ..utils import get_redirect_target

from . import github
from .blueprint import GitHubBlueprint
from .forms import ConsentForm, LeaveForm
Expand Down
8 changes: 4 additions & 4 deletions jazzband/admin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from flask import redirect, url_for, request, session
from flask import redirect, request, session, url_for
from flask_admin import Admin, AdminIndexView, expose
from flask_admin.contrib import sqla
from flask_login import current_user

from .account.models import OAuth
from .auth import current_user_is_roadie
from .db import postgres
from .account.models import OAuth
from .members.models import User, EmailAddress
from .members.models import EmailAddress, User
from .projects.models import (
Project,
ProjectCredential,
ProjectUpload,
ProjectMembership,
ProjectUpload,
)


Expand Down
14 changes: 0 additions & 14 deletions jazzband/assets.py

This file was deleted.

5 changes: 3 additions & 2 deletions jazzband/cli.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sys

import click

from flask.cli import with_appcontext

from .db import postgres, redis
from .members.commands import sync_members, sync_email_addresses
from .projects.commands import sync_projects, send_new_upload_notifications
from .members.commands import sync_email_addresses, sync_members
from .projects.commands import send_new_upload_notifications, sync_projects


@click.command("db")
Expand Down
Loading

0 comments on commit 0673746

Please sign in to comment.