Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CI tests and automate CodeRed Cloud deployment #9

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .cr.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# CodeRed Cloud deployment configuration.

[cr]
# Include some generated files which are gitignored.
deploy_include =
config-prd-stats.json
wagtailspace/static/
60 changes: 60 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Test & Deploy

# This action will be run on the `master` branch
# or on any pull requests going into the `master` branch.
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:

quality-control:
name: Quality Control
runs-on: ubuntu-latest
# Test that Django and the frontend work.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
- uses: actions/setup-node@v4
with:
python-version: 3.8
node-version: 14
- run: pip install -r requirements.txt
- run: python manage.py check
- run: python manage.py makemigrations --check
- run: npm -g install yarn
- run: yarn
- run: yarn build

deploy:
name: Deploy to CodeRed Cloud
# Only run the deployment if the previous checks succeeded.
needs: quality-control
# Only run in the master branch (i.e. not pull requests).
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 14
# Build the frontend, since its output is not part of version control.
- name: Build frontend
run: |
npm -g install yarn
yarn
yarn build
# CodeRed Cloud command line tool.
# See: https://www.codered.cloud/docs/cli/
- name: Install cr tool
run: |
wget -nv -O /usr/local/bin/cr "https://www.codered.cloud/cli/cr-linux"
chmod +x /usr/local/bin/cr
# Run the deployment.
- name: Deploy
run: cr deploy wagtailspace-us
env:
CR_TOKEN: ${{ secrets.CR_TOKEN }}
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 0 additions & 2 deletions CHANGELOG.txt

This file was deleted.

14 changes: 0 additions & 14 deletions codered-deploy.txt

This file was deleted.

74 changes: 28 additions & 46 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,34 @@
Wagtail Space
=============
Wagtail Space US
================

Wagtail Space is a Wagtail event hosted by Four Digits in Arnhem, The Netherlands.
Code for website at: https://us.wagtail.space/, currently hosted on [CodeRed Cloud](https://www.codered.cloud/).

We like others to organise Wagtail Space events as well.

If you like to organise a Wagtail meet up, sprint or conference you may use the Wagtail Space name, graphics and website!

What we propose:

- Name your Wagtail event: 'Wagtail Space [CityName]'. Eg: 'Wagtail Space Philadelphia'.
- Notify Four Digits and get a subdomain (philadelphia.wagtail.space)
- We list your event on [wagtail.space](https://wagtail.space)
- Provide hosting yourself (supply an ip address)
- Notify Wagtail Core team of your event plans


Install
Backend
-------

Clone this repo:

git clone git@github.com:wagtail/wagtailspace-us.git


Create a Python 3.6 environment and install Python packages:
Create a **Python 3.8** environment and install Python packages:

python3 -m venv .venv/
source .venv/bin/activate
pip install -r requirements.txt


Configure your database. Copy and edit local.py. (secret key and database credentials).
Install **Postgres 15** and configure a local database. Copy and edit local.py:

cp wagtailspace/settings/local.py.example wagtailspace/settings/local.py
vi wagtailspace/settings/local.py


Migrate and create a user:

python manage.py migrate
python manage.py createsuperuser

Build front-end:

npm install -g yarn
yarn
yarn build

Runserver:

python manage.py runserver
Expand All @@ -56,19 +37,40 @@ Runserver:
Frontend
--------

Install NodeJS (last tested with version 14). Then install yarn with:
Install **NodeJS 14**. Then install yarn with:

npm install -g yarn

Install project packages:

yarn

Then build the frontend:

yarn build

Run the development web server. This should be run in tandem with Django runserver.

yarn start


Deploying on CodeRed Cloud
--------------------------

The https://us.wagtail.space/ site is currently hosted with [CodeRed Cloud](https://www.codered.cloud/).

**NOTE:** the site will auto-deploy from the master branch on GitHub. However, if you need to manually deploy for some reason, follow the steps below.

Ensure the latest code is committed and pushed to master. Build the frontend locally:

git pull origin master
yarn build

Install the CodeRed deployment tool `pip install cr`. Get an API key from https://app.codered.cloud/

cr deploy wagtailspace-us --token "your_api_key"


Deploying (Generic)
-------------------

Expand All @@ -79,30 +81,10 @@ Build the frontend locally and copy the results to the server:
scp wagtailspace/static user@server.tld:/path/to/wagtailspace/wagtailspace
scp config-prd-stats.json user@server.tld:/path/to/wagtailspace


On the server:

pip install -r requirements.txt
python manage.py collectstatic
python manage.py migrate


Restart.


Deploying on CodeRed Cloud
--------------------------

Build the frontend locally:

git pull origin master
yarn build

Copy the code and static assets to the server using SFTP (credentials can be
accessed through CodeRed dashboard at https://app.codered.cloud/)

cat codered-deploy.txt | sftp wagtailspace-us@wagtailspace-us.codered.cloud

From the CodeRed Dashboard > Websites > Deployment tab click
**Redeploy Production** which will reinitialize the runtime with the new code
(and automatically runs pip install, collectstatic, migrate, etc.).
12 changes: 12 additions & 0 deletions wagtailspace/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'wagtailspace-us',
'USER': 'postgres',
'HOST': 'localhost',
'PASSWORD': 'postgres',
}
}

SECRET_KEY = 'Not a secret!!!'

LOGGING = {
'version': 1,
'disable_existing_loggers': False,
Expand Down
Loading