Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Awoyalejohn committed Jul 17, 2022
0 parents commit 1a8a98a
Show file tree
Hide file tree
Showing 19 changed files with 866 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
core.Microsoft*
core.mongo*
core.python*
env.py
__pycache__/
*.py[cod]
node_modules/
.github/
cloudinary_python.txt
97 changes: 97 additions & 0 deletions .gitpod.dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
FROM gitpod/workspace-base:latest

RUN echo "CI version from base"

### NodeJS ###
USER gitpod
ENV NODE_VERSION=16.13.0
ENV TRIGGER_REBUILD=1
RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | PROFILE=/dev/null bash \
&& bash -c ". .nvm/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& npm install -g typescript yarn node-gyp" \
&& echo ". ~/.nvm/nvm.sh" >> /home/gitpod/.bashrc.d/50-node
ENV PATH=$PATH:/home/gitpod/.nvm/versions/node/v${NODE_VERSION}/bin

### Python ###
USER gitpod
RUN sudo install-packages python3-pip

ENV PATH=$HOME/.pyenv/bin:$HOME/.pyenv/shims:$PATH
RUN curl -fsSL https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash \
&& { echo; \
echo 'eval "$(pyenv init -)"'; \
echo 'eval "$(pyenv virtualenv-init -)"'; } >> /home/gitpod/.bashrc.d/60-python \
&& pyenv update \
&& pyenv install 3.8.11 \
&& pyenv global 3.8.11 \
&& python3 -m pip install --no-cache-dir --upgrade pip \
&& python3 -m pip install --no-cache-dir --upgrade \
setuptools wheel virtualenv pipenv pylint rope flake8 \
mypy autopep8 pep8 pylama pydocstyle bandit notebook \
twine \
&& sudo rm -rf /tmp/*USER gitpod
ENV PYTHONUSERBASE=/workspace/.pip-modules \
PIP_USER=yes
ENV PATH=$PYTHONUSERBASE/bin:$PATH

# Setup Heroku CLI
RUN curl https://cli-assets.heroku.com/install.sh | sh

# Setup MongoDB
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 20691eec35216c63caf66ce1656408e390cfb1f5 && \
sudo sh -c 'echo "deb http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.4.list' && \
sudo apt-get update -y && \
sudo touch /etc/init.d/mongod && \
sudo apt-get install -y mongodb-org-shell && \
sudo apt-get install -y links && \
sudo apt-get clean -y && \
sudo rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* && \
sudo chown -R gitpod:gitpod /home/gitpod/.cache/heroku/

# Setup PostgreSQL

RUN sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" | tee /etc/apt/sources.list.d/pgdg.list' && \
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
sudo apt-get update -y && \
sudo apt-get install -y postgresql-12

ENV PGDATA="/workspace/.pgsql/data"

RUN mkdir -p ~/.pg_ctl/bin ~/.pg_ctl/sockets \
&& echo '#!/bin/bash\n[ ! -d $PGDATA ] && mkdir -p $PGDATA && initdb --auth=trust -D $PGDATA\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" start\n' > ~/.pg_ctl/bin/pg_start \
&& echo '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" stop\n' > ~/.pg_ctl/bin/pg_stop \
&& chmod +x ~/.pg_ctl/bin/*

# ENV DATABASE_URL="postgresql://gitpod@localhost"
# ENV PGHOSTADDR="127.0.0.1"
ENV PGDATABASE="postgres"

ENV PATH="/usr/lib/postgresql/12/bin:/home/gitpod/.nvm/versions/node/v${NODE_VERSION}/bin:$HOME/.pg_ctl/bin:$PATH"


# Add aliases

RUN echo 'alias run="python3 $GITPOD_REPO_ROOT/manage.py runserver 0.0.0.0:8000"' >> ~/.bashrc && \
echo 'alias heroku_config=". $GITPOD_REPO_ROOT/.vscode/heroku_config.sh"' >> ~/.bashrc && \
echo 'alias python=python3' >> ~/.bashrc && \
echo 'alias pip=pip3' >> ~/.bashrc && \
echo 'alias arctictern="python3 $GITPOD_REPO_ROOT/.vscode/arctictern.py"' >> ~/.bashrc && \
echo 'alias font_fix="python3 $GITPOD_REPO_ROOT/.vscode/font_fix.py"' >> ~/.bashrc && \
echo 'alias set_pg="export PGHOSTADDR=127.0.0.1"' >> ~/.bashrc && \
echo 'alias mongosh=mongo' >> ~/.bashrc && \
echo 'alias make_url="python3 $GITPOD_REPO_ROOT/.vscode/make_url.py "' >> ~/.bashrc && \
echo 'FILE="$GITPOD_REPO_ROOT/.vscode/post_upgrade.sh"' >> ~/.bashrc && \
echo 'if [ -z "$POST_UPGRADE_RUN" ]; then' >> ~/.bashrc && \
echo ' if [[ -f "$FILE" ]]; then' >> ~/.bashrc && \
echo ' . "$GITPOD_REPO_ROOT/.vscode/post_upgrade.sh"' >> ~/.bashrc && \
echo " fi" >> ~/.bashrc && \
echo "fi" >> ~/.bashrc

# Local environment variables
# C9USER is temporary to allow the MySQL Gist to run
ENV C9_USER="root"
ENV PORT="8080"
ENV IP="0.0.0.0"
ENV C9_HOSTNAME="localhost"
16 changes: 16 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
image:
file: .gitpod.dockerfile
tasks:
- init: . ${GITPOD_REPO_ROOT}/.vscode/init_tasks.sh
command: /home/gitpod/.pg_ctl/bin/pg_start > /dev/null
- command: . ${GITPOD_REPO_ROOT}/.vscode/uptime.sh &
vscode:
extensions:
- ms-python.python
- formulahendry.auto-close-tag
- eventyret.bootstrap-4-cdn-snippet
- hookyqr.beautify
- matt-rudge.auto-open-preview-panel
- ms-toolsai.jupyter
- ms-toolsai.jupyter-keymap
- ms-toolsai.jupyter-renderers
228 changes: 228 additions & 0 deletions .vscode/MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
# Gitpod Template Maintainer’s Guide

Revision Date: 24th September, 2021

Author(s): Matt Rudge


## Overview

As of 23rd September, 2021, the [Gitpod Full Template](https://github.com/Code-Institute-Org/gitpod-full-template) now has versioning features. Versioning capability is provided by the following files, all in the .vscode directory:

`arctictern.py` - the migration tool to allow the student’s workspace to be updated

`upgrades.json` - a JSON file containing the changes made since the template was last updated

`version.txt` - a text file containing the current version number


## File formats

The upgrades.json file has the following format:

Key: Version number as a string

Value: Bash commands to apply the changes made, separated by \n for newlines

For example, in an earlier version of the template, we removed the `DATABASE_URL` and `PGHOSTADDR` environment variables. To apply these changes to an existing workspace, here is the content of the upgrades.json file:

```json
{

"1.210831": "echo 'unset DATABASE_URL' >> ~/.bashrc\necho 'unset PGHOSTADDR' >> ~/.bashrc"

}
```

The key is the version number, in this case 1.210831. The value is the commands that will be run. In this case, we are appending two `unset` commands to the `.bashrc` file. Each command should be separated by \n to indicate a newline.

The version.txt file is a simple text file with one line, which is the version number.


## Version numbering

Currently, for ease, we are using the major version number 1. The minor version number is the date that the template was changed in YYMMDD format. So, the current version of the template is 1.210923 because it was last modified on September 23rd, 2021.


## Arctic Tern workflow

Students can run the Arctic Tern migration tool by simply typing arctictern in the terminal.

When Arctic Tern is run, it performs the following actions:

1. Retrieve updated versions of the main files
2. Check to see if the version number of the template in the student’s workspace is lower than the template’s current version on GitHub
3. If it is, retrieve and parse the `upgrades.json` file
4. If the version key in the `upgrades.json` file is greater than the student’s template version then add the commands in the value to the `post_upgrade.sh` file

When Arctic Tern has finished, the student should add, commit and push the changes to GitHub. If they want the changes to take effect immediately, then they should restart their workspace.

If the `post_upgrade.sh` file exists in the `.vscode` directory, then it will be run once when the workspace is started.


## Updates for students running prior versions of the template

Because of a current bug in how Gitpod parses the `.gitpod.yml` file, students who are using a version of the template older than 1.210923 (which is the vast majority) will not be able to take advantage of these features without recreating their workspace.

The workaround for them is to:

1. Download and run `arctictern.py` in their current workspace.
2. Add, commit and push to GitHub.
3. Open the workspace using the green Gitpod button from GitHub
4. Manually copy over any env.py or SQLite databases from the old workspace


## Process for adding changes to the template

If you need to update or change the template, then please follow this procedure:


### Fork the template

Create a fork in your own GitHub repository and work from there. Do not work on the template directly in the Org repo.


### Determine the changes that need to be made

In determining the changes that need to be made, please keep in mind which files will need to be adjusted.

Some files do not need to have their changes reflected in the upgrades.json file. Use the following table to decide:


<table>
<tr>
<td style="background-color: orange; color: white"><strong>Filename</strong>
</td>
<td style="background-color: orange; color: white"><strong>Changes to be</strong>
<p>
<strong>reflected in upgrade.json?</strong>
</td>
</tr>
<tr>
<td>.gitignore
</td>
<td>No
</td>
</tr>
<tr>
<td>.gitpod.yml
</td>
<td>No
</td>
</tr>
<tr>
<td>.gitpod.dockerfile
</td>
<td>Yes
</td>
</tr>
<tr>
<td>README.md
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/arctictern.py
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/client.cnf
</td>
<td>Yes
</td>
</tr>
<tr>
<td>.vscode/font_fix.py
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/heroku_config.sh
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/init_tasks.sh
</td>
<td>Yes
</td>
</tr>
<tr>
<td>.vscode/launch.json
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/mysql.cnf
</td>
<td>Yes
</td>
</tr>
<tr>
<td>.vscode/settings.json
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/start_mysql.sh
</td>
<td>Yes
</td>
</tr>
<tr>
<td>.vscode/upgrades.json
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/uptime.sh
</td>
<td>No
</td>
</tr>
<tr>
<td>.vscode/version.txt
</td>
<td>No
</td>
</tr>
</table>



### Make and test your changes

Do this in your local repo and confirm that everything works as expected.


### Change the version number in version.txt

Update the version number using the format specified above.


### Update the upgrades.json file if necessary

If the `upgrades.json` file does need to be updated, then add a key at the end of the dictionary with the version number.

The value should be the commands that will be run at the end of `.bashrc` to apply your changes. Bear in mind that these commands may be different to the ones you have added to the other files.


### Update the README.md file

Add the updated date, version and any changes that have been made to the change log. Note that if you have opened your forked template in Gitpod then it will have substituted USER_NAME at the top of the README file with your GitHub username, so change it back to USER_NAME before committing.


### Create a PR

Create a pull request against the original repo and assign at least one reviewer.


### And relax...
Loading

0 comments on commit 1a8a98a

Please sign in to comment.