From 1a8a98a0a38af0df169ae08dcf7443eb591d296b Mon Sep 17 00:00:00 2001
From: Awoyalejohn <88907733+Awoyalejohn@users.noreply.github.com>
Date: Sun, 17 Jul 2022 14:42:30 +0100
Subject: [PATCH] Initial commit
---
.gitignore | 9 ++
.gitpod.dockerfile | 97 +++++++++++++++++
.gitpod.yml | 16 +++
.vscode/MAINTAINERS.md | 228 +++++++++++++++++++++++++++++++++++++++
.vscode/arctictern.py | 197 +++++++++++++++++++++++++++++++++
.vscode/client.cnf | 10 ++
.vscode/font_fix.py | 22 ++++
.vscode/heroku_config.sh | 26 +++++
.vscode/init_tasks.sh | 23 ++++
.vscode/launch.json | 14 +++
.vscode/make_url.py | 14 +++
.vscode/mysql.cnf | 25 +++++
.vscode/rmdep.sh | 5 +
.vscode/settings.json | 27 +++++
.vscode/start_mysql.sh | 17 +++
.vscode/upgrades.json | 4 +
.vscode/uptime.sh | 23 ++++
.vscode/version.txt | 1 +
README.md | 108 +++++++++++++++++++
19 files changed, 866 insertions(+)
create mode 100644 .gitignore
create mode 100644 .gitpod.dockerfile
create mode 100644 .gitpod.yml
create mode 100644 .vscode/MAINTAINERS.md
create mode 100644 .vscode/arctictern.py
create mode 100644 .vscode/client.cnf
create mode 100644 .vscode/font_fix.py
create mode 100644 .vscode/heroku_config.sh
create mode 100644 .vscode/init_tasks.sh
create mode 100644 .vscode/launch.json
create mode 100644 .vscode/make_url.py
create mode 100644 .vscode/mysql.cnf
create mode 100644 .vscode/rmdep.sh
create mode 100644 .vscode/settings.json
create mode 100644 .vscode/start_mysql.sh
create mode 100644 .vscode/upgrades.json
create mode 100644 .vscode/uptime.sh
create mode 100644 .vscode/version.txt
create mode 100644 README.md
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c7bfd08
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,9 @@
+core.Microsoft*
+core.mongo*
+core.python*
+env.py
+__pycache__/
+*.py[cod]
+node_modules/
+.github/
+cloudinary_python.txt
diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile
new file mode 100644
index 0000000..efd046b
--- /dev/null
+++ b/.gitpod.dockerfile
@@ -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"
diff --git a/.gitpod.yml b/.gitpod.yml
new file mode 100644
index 0000000..601706c
--- /dev/null
+++ b/.gitpod.yml
@@ -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
diff --git a/.vscode/MAINTAINERS.md b/.vscode/MAINTAINERS.md
new file mode 100644
index 0000000..2eac1fe
--- /dev/null
+++ b/.vscode/MAINTAINERS.md
@@ -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:
+
+
+
+
+ Filename
+ |
+ Changes to be
+
+reflected in upgrade.json?
+ |
+
+
+ .gitignore
+ |
+ No
+ |
+
+
+ .gitpod.yml
+ |
+ No
+ |
+
+
+ .gitpod.dockerfile
+ |
+ Yes
+ |
+
+
+ README.md
+ |
+ No
+ |
+
+
+ .vscode/arctictern.py
+ |
+ No
+ |
+
+
+ .vscode/client.cnf
+ |
+ Yes
+ |
+
+
+ .vscode/font_fix.py
+ |
+ No
+ |
+
+
+ .vscode/heroku_config.sh
+ |
+ No
+ |
+
+
+ .vscode/init_tasks.sh
+ |
+ Yes
+ |
+
+
+ .vscode/launch.json
+ |
+ No
+ |
+
+
+ .vscode/mysql.cnf
+ |
+ Yes
+ |
+
+
+ .vscode/settings.json
+ |
+ No
+ |
+
+
+ .vscode/start_mysql.sh
+ |
+ Yes
+ |
+
+
+ .vscode/upgrades.json
+ |
+ No
+ |
+
+
+ .vscode/uptime.sh
+ |
+ No
+ |
+
+
+ .vscode/version.txt
+ |
+ No
+ |
+
+
+
+
+
+### 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...
diff --git a/.vscode/arctictern.py b/.vscode/arctictern.py
new file mode 100644
index 0000000..7941e9f
--- /dev/null
+++ b/.vscode/arctictern.py
@@ -0,0 +1,197 @@
+"""
+arctictern.py
+A little script that does a big migration
+"""
+
+import json
+import os
+import requests
+import shutil
+import subprocess
+import sys
+from os.path import exists
+
+BASE_URL = "https://raw.githubusercontent.com/Code-Institute-Org/gitpod-full-template/master/"
+
+BACKUP = True
+MIGRATE = False
+CURRENT_VERSION = 1.0
+THIS_VERSION = 1.0
+
+
+MIGRATE_FILE_LIST = [{"filename": ".theia/settings.json",
+ "url": ".vscode/settings.json"
+ },
+ {"filename": ".gitpod.yml",
+ "url": ".gitpod.yml"
+ },
+ {"filename": ".gitpod.dockerfile",
+ "url": ".gitpod.dockerfile"
+ },
+ {"filename": ".theia/heroku_config.sh",
+ "url": ".vscode/heroku_config.sh"
+ },
+ {"filename": ".theia/uptime.sh",
+ "url": ".vscode/uptime.sh"
+ },
+ {"filename": ".theia/init_tasks.sh",
+ "url": ".vscode/init_tasks.sh"
+ }]
+
+UPGRADE_FILE_LIST = [{"filename": ".vscode/client.cnf",
+ "url": ".vscode/client.cnf"
+ },
+ {"filename": ".vscode/mysql.cnf",
+ "url": ".vscode/mysql.cnf"
+ },
+ {"filename": ".vscode/settings.json",
+ "url": ".vscode/settings.json"
+ },
+ {"filename": ".vscode/launch.json",
+ "url": ".vscode/launch.json"
+ },
+ {"filename": ".gitpod.yml",
+ "url": ".gitpod.yml"
+ },
+ {"filename": ".gitpod.dockerfile",
+ "url": ".gitpod.dockerfile"
+ },
+ {"filename": ".vscode/heroku_config.sh",
+ "url": ".vscode/heroku_config.sh"
+ },
+ {"filename": ".vscode/init_tasks.sh",
+ "url": ".vscode/init_tasks.sh"
+ },
+ {"filename": ".vscode/uptime.sh",
+ "url": ".vscode/uptime.sh"
+ },
+ {"filename": ".vscode/make_url.py",
+ "url": ".vscode/make_url.py"
+ },
+ {"filename": ".vscode/arctictern.py",
+ "url": ".vscode/arctictern.py"
+ }]
+
+FINAL_LINES = "\nexport POST_UPGRADE_RUN=1\nsource ~/.bashrc\n"
+
+
+def needs_upgrade():
+ """
+ Checks the version of the current template against
+ this version.
+ Returns True if upgrade is needed, False if not.
+ """
+
+ if exists(".vscode/version.txt"):
+ with open(".vscode/version.txt", "r") as f:
+ THIS_VERSION = float(f.read().strip())
+ else:
+ THIS_VERSION = 1.0
+ with open(".vscode/version.txt", "w") as f:
+ f.write(str(THIS_VERSION))
+
+ r = requests.get(BASE_URL + ".vscode/version.txt")
+ CURRENT_VERSION = float(r.content)
+ print(f"Upstream version: {CURRENT_VERSION}")
+ print(f"Local version: {THIS_VERSION}")
+
+ return CURRENT_VERSION > THIS_VERSION
+
+
+def build_post_upgrade():
+
+ r = requests.get(BASE_URL + ".vscode/upgrades.json")
+ upgrades = json.loads(r.content.decode("utf-8"))
+ content = ""
+
+ for k,v in upgrades.items():
+ if float(k) > THIS_VERSION:
+ print(f"Adding version changes for {k} to post_upgrade.sh")
+ content += v
+
+ if content:
+ content += FINAL_LINES
+ with open(".vscode/post_upgrade.sh", "w") as f:
+ f.writelines(content)
+
+ print("Built post_upgrade.sh. Restart your workspace for it to take effect")
+
+
+def process(file, suffix):
+ """
+ Replaces and optionally backs up the files that
+ need to be changed.
+ Arguments: file - a path and filename
+ suffix - the suffix to the BASE_URL
+ """
+
+ if BACKUP:
+ try:
+ shutil.copyfile(file, f"{file}.bak")
+ except FileNotFoundError:
+ print(f"{file} not found, a new one will be created")
+
+ with open(file, "wb") as f:
+ r = requests.get(BASE_URL + suffix)
+ f.write(r.content)
+
+
+def start_migration():
+ """
+ Calls the process function and
+ renames the directory
+ """
+ if not os.path.isdir(".theia") and MIGRATE:
+ sys.exit("The .theia directory does not exist")
+
+ FILE_LIST = MIGRATE_FILE_LIST if MIGRATE else UPGRADE_FILE_LIST
+
+ if not MIGRATE and not os.path.isdir(".vscode"):
+ print("Creating .vscode directory")
+ os.mkdir(".vscode")
+
+ for file in FILE_LIST:
+ print(f"Processing: {file['filename']}")
+ process(file["filename"], file["url"])
+
+ if MIGRATE and os.path.isdir(".vscode"):
+ print(".vscode directory already exists")
+ if input("Overwrite? Y/N ").lower() == "y":
+ shutil.rmtree(".vscode")
+ else:
+ print("You will need to manually remove the .theia directory after migration.")
+
+ if MIGRATE and not os.path.isdir(".vscode"):
+ print("Renaming directory")
+ os.rename(".theia", ".vscode")
+
+ if not MIGRATE and needs_upgrade():
+ build_post_upgrade()
+
+ print("Changes saved.")
+ print("Please add, commit and push to GitHub.")
+ print("You may need to stop and restart your workspace for")
+ print("the changes to take effect.")
+
+
+if __name__ == "__main__":
+
+ BACKUP = "--nobackup" not in sys.argv
+ MIGRATE = "--migrate" in sys.argv
+
+ print("CI Template Migration Utility 0.2")
+ print("---------------------------------")
+ print("The default action is to upgrade the workspace to the latest version.")
+ print(f"Usage: python3 {sys.argv[0]} [--nobackup --migrate]")
+
+ if not BACKUP:
+ print("If the --nobackup switch is provided, then changed files will not be backed up.")
+ if not MIGRATE:
+ print("If the --migrate switch is provided, the repo will be migrated from Theia to VS Code")
+
+ print()
+
+ if input("Start? Y/N ").lower() == "y":
+ start_migration()
+ else:
+ sys.exit("Migration cancelled by the user")
diff --git a/.vscode/client.cnf b/.vscode/client.cnf
new file mode 100644
index 0000000..12dcd7a
--- /dev/null
+++ b/.vscode/client.cnf
@@ -0,0 +1,10 @@
+[client]
+host = localhost
+user = root
+password =
+socket = /var/run/mysqld/mysqld.sock
+[mysql_upgrade]
+host = localhost
+user = root
+password =
+socket = /var/run/mysqld/mysqld.sock
diff --git a/.vscode/font_fix.py b/.vscode/font_fix.py
new file mode 100644
index 0000000..81e8816
--- /dev/null
+++ b/.vscode/font_fix.py
@@ -0,0 +1,22 @@
+# Fixes the font issue on Brave browser
+# Matt Rudge
+# August 2021
+
+import json
+import os
+
+BASE_PATH = os.environ.get("GITPOD_REPO_ROOT")
+
+with open(f"{BASE_PATH}/.vscode/settings.json", "r+") as f:
+ content = json.loads(f.read())
+
+ if "terminal.integrated.fontFamily" not in content:
+ print("Adding wider and higher font settings")
+ content["terminal.integrated.lineHeight"] = 1.2
+ content["terminal.integrated.letterSpacing"] = 2
+ else:
+ print("Wider and higher font settings already added!")
+
+ f.seek(0, os.SEEK_SET)
+ f.write(json.dumps(content))
+ f.truncate()
diff --git a/.vscode/heroku_config.sh b/.vscode/heroku_config.sh
new file mode 100644
index 0000000..f842c96
--- /dev/null
+++ b/.vscode/heroku_config.sh
@@ -0,0 +1,26 @@
+#!/bin/bash
+# Script to allow Heroku API key to be pasted
+# exported as an environment variable
+#
+# Matt Rudge, May 2021
+
+echo Heroku authentication configuration script
+echo Code Institute, 2021
+echo
+echo Get your Heroku API key by going to https://dashboard.heroku.com
+echo Go to Account Settings and click on Reveal to view your Heroku API key
+echo
+
+if [[ -z "${HEROKU_API_KEY}" ]]; then
+ echo Paste your Heroku API key here or press Enter to quit:
+ read apikey
+ if [[ -z "${apikey}" ]]; then
+ return 0
+ fi
+ echo export HEROKU_API_KEY=${apikey} >> ~/.bashrc
+ echo Added the export. Refreshing the terminal.
+ . ~/.bashrc > /dev/null
+ echo Done!
+else
+ echo API key is already set. Exiting
+fi
diff --git a/.vscode/init_tasks.sh b/.vscode/init_tasks.sh
new file mode 100644
index 0000000..33b035a
--- /dev/null
+++ b/.vscode/init_tasks.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# Creates a user record for the current Cloud9 user
+# Gives a personalised greeting
+# Adds configuration options for SQLite
+# Creates run aliases
+# Author: Matt Rudge
+
+echo "Setting the greeting"
+sed -i "s/USER_NAME/$GITPOD_GIT_USER_NAME/g" ${GITPOD_REPO_ROOT}/README.md
+echo "Creating the gitpod user in MySQL"
+RESULT="$(mysql -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'gitpod')")"
+if [ "$RESULT" = 1 ]; then
+ echo "gitpod already exists"
+else
+ mysql -e "CREATE USER 'gitpod'@'%' IDENTIFIED BY '';" -u root
+ echo "Granting privileges"
+ mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'gitpod'@'%' WITH GRANT OPTION;" -u root
+fi
+echo "Creating .sqliterc file"
+echo ".headers on" > ~/.sqliterc
+echo ".mode column" >> ~/.sqliterc
+echo "Your workspace is ready to use. Happy coding!"
diff --git a/.vscode/launch.json b/.vscode/launch.json
new file mode 100644
index 0000000..d9e387c
--- /dev/null
+++ b/.vscode/launch.json
@@ -0,0 +1,14 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "name": "Python: Current File (Integrated Terminal)",
+ "type": "python",
+ "request": "launch",
+ "program": "${file}",
+ "console": "internalConsole"
+ }
+ ]
+}
diff --git a/.vscode/make_url.py b/.vscode/make_url.py
new file mode 100644
index 0000000..1a27167
--- /dev/null
+++ b/.vscode/make_url.py
@@ -0,0 +1,14 @@
+# Simple utility for creating the Cloudinary URL from a
+# cloudinary_python.txt file
+# Matt Rudge, November 2021
+
+import re
+
+with open("cloudinary_python.txt") as f:
+ content = f.readlines()
+
+cloud_name = re.findall(r"['](.*?)[']",content[15])[0]
+api_key = re.findall(r"['](.*?)[']",content[16])[0]
+api_secret = re.findall(r"['](.*?)[']",content[17])[0]
+
+print(f"cloudinary://{api_key}:{api_secret}@{cloud_name}")
diff --git a/.vscode/mysql.cnf b/.vscode/mysql.cnf
new file mode 100644
index 0000000..1fd3264
--- /dev/null
+++ b/.vscode/mysql.cnf
@@ -0,0 +1,25 @@
+[mysqld_safe]
+socket = /var/run/mysqld/mysqld.sock
+nice = 0
+
+[mysqld]
+user = gitpod
+pid-file = /var/run/mysqld/mysqld.pid
+socket = /var/run/mysqld/mysqld.sock
+port = 3306
+basedir = /usr
+datadir = /workspace/mysql
+tmpdir = /tmp
+lc-messages-dir = /usr/share/mysql
+skip-external-locking
+
+key_buffer_size = 16M
+max_allowed_packet = 16M
+thread_stack = 192K
+thread_cache_size = 8
+
+myisam-recover-options = BACKUP
+
+general_log_file = /var/log/mysql/mysql.log
+general_log = 1
+log_error = /var/log/mysql/error.log
diff --git a/.vscode/rmdep.sh b/.vscode/rmdep.sh
new file mode 100644
index 0000000..027faf4
--- /dev/null
+++ b/.vscode/rmdep.sh
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+echo "Removing all Python dependencies"
+pip3 uninstall -y -r <(pip3 freeze) > /dev/null
+echo "Done!"
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..53f621b
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,27 @@
+{
+ "python.linting.pylintEnabled": true,
+ "python.linting.enabled": true,
+ "python.linting.pep8Enabled": false,
+ "python.linting.flake8Enabled": true,
+ "python.terminal.activateEnvironment": false,
+ "python.formatting.autopep8Path": "/home/gitpod/.pyenv/shims/autopep8",
+ "python.linting.flake8Path": "/home/gitpod/.pyenv/shims/flake8",
+ "cornflakes.linter.executablePath": "/home/gitpod/.pyenv/shims/flake8",
+ "files.exclude": {
+ "**/.DS_Store": true,
+ "**/.git": true,
+ "**/.github": true,
+ "**/.gitp*": true,
+ "**/.hg": true,
+ "**/.svn": true,
+ "**/.vscode": true,
+ "**/core.Microsoft*": true,
+ "**/core.mongo*": true,
+ "**/core.python*": true,
+ "**/CVS": true
+ },
+ "files.autoSave": "off",
+ "workbench.colorTheme": "Visual Studio Dark",
+ "terminal.integrated.gpuAcceleration": "canvas",
+ "editor.defaultFormatter": "HookyQR.beautify"
+}
diff --git a/.vscode/start_mysql.sh b/.vscode/start_mysql.sh
new file mode 100644
index 0000000..1872562
--- /dev/null
+++ b/.vscode/start_mysql.sh
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+# this script is intended to be called from .bashrc
+# This is a workaround for not having something like supervisord
+
+if [ ! -e /var/run/mysqld/gitpod-init.lock ]
+then
+ touch /var/run/mysqld/gitpod-init.lock
+
+ # initialize database structures on disk, if needed
+ [ ! -d /workspace/mysql ] && mysqld --initialize-insecure
+
+ # launch database, if not running
+ [ ! -e /var/run/mysqld/mysqld.pid ] && mysqld --daemonize
+
+ rm /var/run/mysqld/gitpod-init.lock
+fi
diff --git a/.vscode/upgrades.json b/.vscode/upgrades.json
new file mode 100644
index 0000000..d5e3652
--- /dev/null
+++ b/.vscode/upgrades.json
@@ -0,0 +1,4 @@
+{
+ "1.210831": "echo 'unset DATABASE_URL' >> ~/.bashrc\necho 'unset PGHOSTADDR' >> ~/.bashrc\n",
+ "1.211118": "echo 'alias make_url=\"python3 $GITPOD_REPO_ROOT/.vscode/make_url.py\"' >> ~/.bashrc\n",
+}
diff --git a/.vscode/uptime.sh b/.vscode/uptime.sh
new file mode 100644
index 0000000..25a37f8
--- /dev/null
+++ b/.vscode/uptime.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+# Pings the webhook so that we can gather
+# basic usage stats. No personally identifiable
+# data is captured here, and it is impossible to
+# identify an individual user from the captured data.
+# Matt Rudge, April 2021
+
+UUID=$(cat /proc/sys/kernel/random/uuid)
+URL=https://1xthkmzwg3.execute-api.eu-west-1.amazonaws.com/prod/lrsapi/
+API_KEY=jceBCdeGZP9RDeUNCfM4jIQ39Cx0jtG51QgcwDwc
+VERB="started"
+
+clear
+
+while true; do
+
+ DATA="{\"activity_time\":\"$(date +%Y-%m-%dT%H:%M:%S).000Z\",\"actor\":\"${UUID}\",\"verb\":\"${VERB}\",\"activity_object\":\"Gitpod Workspace\",\"extra_data\":\"{}\"}"
+ curl -s -X POST -H "x-api-key: ${API_KEY}" -d "${DATA}" ${URL} 1> /dev/null
+ VERB="running"
+ sleep 300
+
+done
diff --git a/.vscode/version.txt b/.vscode/version.txt
new file mode 100644
index 0000000..fc239d7
--- /dev/null
+++ b/.vscode/version.txt
@@ -0,0 +1 @@
+1.211203
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..610bf08
--- /dev/null
+++ b/README.md
@@ -0,0 +1,108 @@
+
+
+Welcome USER_NAME,
+
+This is the Code Institute student template for Gitpod. We have preinstalled all of the tools you need to get started. It's perfectly ok to use this template as the basis for your project submissions.
+
+You can safely delete this README.md file, or change it for your own project. Please do read it at least once, though! It contains some important information about Gitpod and the extensions we use. Some of this information has been updated since the video content was created. The last update to this file was: **September 1, 2021**
+
+## Gitpod Reminders
+
+To run a frontend (HTML, CSS, Javascript only) application in Gitpod, in the terminal, type:
+
+`python3 -m http.server`
+
+A blue button should appear to click: _Make Public_,
+
+Another blue button should appear to click: _Open Browser_.
+
+To run a backend Python file, type `python3 app.py`, if your Python file is named `app.py` of course.
+
+A blue button should appear to click: _Make Public_,
+
+Another blue button should appear to click: _Open Browser_.
+
+In Gitpod you have superuser security privileges by default. Therefore you do not need to use the `sudo` (superuser do) command in the bash terminal in any of the lessons.
+
+To log into the Heroku toolbelt CLI:
+
+1. Log in to your Heroku account and go to *Account Settings* in the menu under your avatar.
+2. Scroll down to the *API Key* and click *Reveal*
+3. Copy the key
+4. In Gitpod, from the terminal, run `heroku_config`
+5. Paste in your API key when asked
+
+You can now use the `heroku` CLI program - try running `heroku apps` to confirm it works. This API key is unique and private to you so do not share it. If you accidentally make it public then you can create a new one with _Regenerate API Key_.
+
+------
+
+## Release History
+
+We continually tweak and adjust this template to help give you the best experience. Here is the version history:
+
+**September 1 2021:** Remove `PGHOSTADDR` environment variable.
+
+**July 19 2021:** Remove `font_fix` script now that the terminal font issue is fixed.
+
+**July 2 2021:** Remove extensions that are not available in Open VSX.
+
+**June 30 2021:** Combined the P4 and P5 templates into one file, added the uptime script. See the FAQ at the end of this file.
+
+**June 10 2021:** Added: `font_fix` script and alias to fix the Terminal font issue
+
+**May 10 2021:** Added `heroku_config` script to allow Heroku API key to be stored as an environment variable.
+
+**April 7 2021:** Upgraded the template for VS Code instead of Theia.
+
+**October 21 2020:** Versions of the HTMLHint, Prettier, Bootstrap4 CDN and Auto Close extensions updated. The Python extension needs to stay the same version for now.
+
+**October 08 2020:** Additional large Gitpod files (`core.mongo*` and `core.python*`) are now hidden in the Explorer, and have been added to the `.gitignore` by default.
+
+**September 22 2020:** Gitpod occasionally creates large `core.Microsoft` files. These are now hidden in the Explorer. A `.gitignore` file has been created to make sure these files will not be committed, along with other common files.
+
+**April 16 2020:** The template now automatically installs MySQL instead of relying on the Gitpod MySQL image. The message about a Python linter not being installed has been dealt with, and the set-up files are now hidden in the Gitpod file explorer.
+
+**April 13 2020:** Added the _Prettier_ code beautifier extension instead of the code formatter built-in to Gitpod.
+
+**February 2020:** The initialisation files now _do not_ auto-delete. They will remain in your project. You can safely ignore them. They just make sure that your workspace is configured correctly each time you open it. It will also prevent the Gitpod configuration popup from appearing.
+
+**December 2019:** Added Eventyret's Bootstrap 4 extension. Type `!bscdn` in a HTML file to add the Bootstrap boilerplate. Check out the README.md file at the official repo for more options.
+
+------
+
+## FAQ about the uptime script
+
+**Why have you added this script?**
+
+It will help us to calculate how many running workspaces there are at any one time, which greatly helps us with cost and capacity planning. It will help us decide on the future direction of our cloud-based IDE strategy.
+
+**How will this affect me?**
+
+For everyday usage of Gitpod, it doesn’t have any effect at all. The script only captures the following data:
+
+- An ID that is randomly generated each time the workspace is started.
+- The current date and time
+- The workspace status of “started” or “running”, which is sent every 5 minutes.
+
+It is not possible for us or anyone else to trace the random ID back to an individual, and no personal data is being captured. It will not slow down the workspace or affect your work.
+
+**So….?**
+
+We want to tell you this so that we are being completely transparent about the data we collect and what we do with it.
+
+**Can I opt out?**
+
+Yes, you can. Since no personally identifiable information is being captured, we'd appreciate it if you let the script run; however if you are unhappy with the idea, simply run the following commands from the terminal window after creating the workspace, and this will remove the uptime script:
+
+```
+pkill uptime.sh
+rm .vscode/uptime.sh
+```
+
+**Anything more?**
+
+Yes! We'd strongly encourage you to look at the source code of the `uptime.sh` file so that you know what it's doing. As future software developers, it will be great practice to see how these shell scripts work.
+
+---
+
+Happy coding!