Skip to content

Commit 8915bba

Browse files
committed
Deployment commit
0 parents  commit 8915bba

21 files changed

+721
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
core.Microsoft*
2+
core.mongo*
3+
core.python*
4+
env.py
5+
__pycache__/
6+
*.py[cod]
7+
node_modules/
8+
.github/

.gitpod.dockerfile

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
FROM gitpod/workspace-full
2+
3+
# Setup Heroku CLI
4+
RUN curl https://cli-assets.heroku.com/install.sh | sh
5+
6+
# Setup Python linters
7+
8+
RUN pip3 install flake8 flake8-flask flake8-django
9+
10+
# Setup MongoDB and MySQL
11+
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 20691eec35216c63caf66ce1656408e390cfb1f5 && \
12+
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' && \
13+
sudo apt-get update -y && \
14+
sudo touch /etc/init.d/mongod && \
15+
sudo apt-get install -y mongodb-org-shell && \
16+
sudo apt-get install -y links && \
17+
sudo apt-get install -y mysql-server && \
18+
sudo apt-get clean -y && \
19+
sudo rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* && \
20+
sudo mkdir /var/run/mysqld && \
21+
sudo chown -R gitpod:gitpod /etc/mysql /var/run/mysqld /var/log/mysql /var/lib/mysql /var/lib/mysql-files /var/lib/mysql-keyring /var/lib/mysql-upgrade /home/gitpod/.cache/heroku/
22+
23+
# Setup PostgreSQL
24+
25+
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' && \
26+
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv B97B0AFCAA1A47F044F244A07FCC7D46ACCC4CF8 && \
27+
sudo apt-get update -y && \
28+
sudo apt-get install -y postgresql-12
29+
30+
ENV PGDATA="/workspace/.pgsql/data"
31+
32+
RUN mkdir -p ~/.pg_ctl/bin ~/.pg_ctl/sockets \
33+
&& 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 \
34+
&& echo '#!/bin/bash\npg_ctl -D $PGDATA -l ~/.pg_ctl/log -o "-k ~/.pg_ctl/sockets" stop\n' > ~/.pg_ctl/bin/pg_stop \
35+
&& chmod +x ~/.pg_ctl/bin/*
36+
37+
# ENV DATABASE_URL="postgresql://gitpod@localhost"
38+
ENV PGHOSTADDR="127.0.0.1"
39+
ENV PGDATABASE="postgres"
40+
41+
# Upgrade Node
42+
43+
ENV NODE_VERSION=14.15.4
44+
RUN bash -c ". .nvm/nvm.sh && \
45+
nvm install ${NODE_VERSION} && \
46+
nvm alias default ${NODE_VERSION} && \
47+
npm install -g yarn"
48+
49+
ENV PATH="/usr/lib/postgresql/12/bin:/home/gitpod/.nvm/versions/node/v${NODE_VERSION}/bin:$HOME/.pg_ctl/bin:$PATH"
50+
51+
# Create our own config files
52+
53+
COPY .vscode/mysql.cnf /etc/mysql/mysql.conf.d/mysqld.cnf
54+
55+
COPY .vscode/client.cnf /etc/mysql/mysql.conf.d/client.cnf
56+
57+
COPY .vscode/start_mysql.sh /etc/mysql/mysql-bashrc-launch.sh
58+
59+
# Start MySQL when we log in
60+
# Add aliases
61+
62+
RUN echo 'alias run="python3 $GITPOD_REPO_ROOT/manage.py runserver 0.0.0.0:8000"' >> ~/.bashrc && \
63+
echo 'alias heroku_config=". $GITPOD_REPO_ROOT/.vscode/heroku_config.sh"' >> ~/.bashrc && \
64+
echo 'alias python=python3' >> ~/.bashrc && \
65+
echo 'alias pip=pip3' >> ~/.bashrc && \
66+
echo 'alias font_fix="python3 $GITPOD_REPO_ROOT/.vscode/font_fix.py"' >> ~/.bashrc && \
67+
echo ". /etc/mysql/mysql-bashrc-launch.sh" >> ~/.bashrc
68+
69+
# Local environment variables
70+
# C9USER is temporary to allow the MySQL Gist to run
71+
ENV C9_USER="root"
72+
ENV PORT="8080"
73+
ENV IP="0.0.0.0"
74+
ENV C9_HOSTNAME="localhost"

.gitpod.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
image:
2+
file: .gitpod.dockerfile
3+
tasks:
4+
- init: . ${GITPOD_REPO_ROOT}/.vscode/init_tasks.sh
5+
command: /home/gitpod/.pg_ctl/bin/pg_start > /dev/null
6+
- command: . ${GITPOD_REPO_ROOT}/.vscode/uptime.sh &
7+
vscode:
8+
extensions:
9+
- ms-python.python
10+
- formulahendry.auto-close-tag
11+
- eventyret.bootstrap-4-cdn-snippet
12+
- hookyqr.beautify
13+
- matt-rudge.auto-open-preview-panel

.vscode/client.cnf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[client]
2+
host = localhost
3+
user = root
4+
password =
5+
socket = /var/run/mysqld/mysqld.sock
6+
[mysql_upgrade]
7+
host = localhost
8+
user = root
9+
password =
10+
socket = /var/run/mysqld/mysqld.sock

.vscode/font_fix.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Fixes the font issue on Brave browser
2+
# Matt Rudge
3+
# August 2021
4+
5+
import json
6+
import os
7+
8+
BASE_PATH = os.environ.get("GITPOD_REPO_ROOT")
9+
10+
with open(f"{BASE_PATH}/.vscode/settings.json", "r+") as f:
11+
content = json.loads(f.read())
12+
13+
if "terminal.integrated.fontFamily" not in content:
14+
print("Adding wider and higher font settings")
15+
content["terminal.integrated.lineHeight"] = 1.2
16+
content["terminal.integrated.letterSpacing"] = 2
17+
else:
18+
print("Wider and higher font settings already added!")
19+
20+
f.seek(0, os.SEEK_SET)
21+
f.write(json.dumps(content))
22+
f.truncate()

.vscode/heroku_config.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Script to allow Heroku API key to be pasted
3+
# exported as an environment variable
4+
#
5+
# Matt Rudge, May 2021
6+
7+
echo Heroku authentication configuration script
8+
echo Code Institute, 2021
9+
echo
10+
echo Get your Heroku API key by going to https://dashboard.heroku.com
11+
echo Go to Account Settings and click on Reveal to view your Heroku API key
12+
echo
13+
14+
if [[ -z "${HEROKU_API_KEY}" ]]; then
15+
echo Paste your Heroku API key here or press Enter to quit:
16+
read apikey
17+
if [[ -z "${apikey}" ]]; then
18+
return 0
19+
fi
20+
echo export HEROKU_API_KEY=${apikey} >> ~/.bashrc
21+
echo Added the export. Refreshing the terminal.
22+
. ~/.bashrc > /dev/null
23+
echo Done!
24+
else
25+
echo API key is already set. Exiting
26+
fi

.vscode/init_tasks.sh

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
# Creates a user record for the current Cloud9 user
4+
# Gives a personalised greeting
5+
# Adds configuration options for SQLite
6+
# Creates run aliases
7+
# Author: Matt Rudge
8+
9+
echo "Setting the greeting"
10+
sed -i "s/USER_NAME/$GITPOD_GIT_USER_NAME/g" ${GITPOD_REPO_ROOT}/README.md
11+
echo "Creating the gitpod user in MySQL"
12+
RESULT="$(mysql -sse "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'gitpod')")"
13+
if [ "$RESULT" = 1 ]; then
14+
echo "gitpod already exists"
15+
else
16+
mysql -e "CREATE USER 'gitpod'@'%' IDENTIFIED BY '';" -u root
17+
echo "Granting privileges"
18+
mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'gitpod'@'%' WITH GRANT OPTION;" -u root
19+
fi
20+
echo "Creating .sqliterc file"
21+
echo ".headers on" > ~/.sqliterc
22+
echo ".mode column" >> ~/.sqliterc
23+
echo "Your workspace is ready to use. Happy coding!"
24+
25+
# Open README.md file
26+
code README.md

.vscode/launch.json

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
"version": "0.2.0",
5+
"configurations": [
6+
{
7+
"name": "Python: Current File (Integrated Terminal)",
8+
"type": "python",
9+
"request": "launch",
10+
"program": "${file}",
11+
"console": "internalConsole"
12+
}
13+
]
14+
}

.vscode/mysql.cnf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[mysqld_safe]
2+
socket = /var/run/mysqld/mysqld.sock
3+
nice = 0
4+
5+
[mysqld]
6+
user = gitpod
7+
pid-file = /var/run/mysqld/mysqld.pid
8+
socket = /var/run/mysqld/mysqld.sock
9+
port = 3306
10+
basedir = /usr
11+
datadir = /workspace/mysql
12+
tmpdir = /tmp
13+
lc-messages-dir = /usr/share/mysql
14+
skip-external-locking
15+
16+
key_buffer_size = 16M
17+
max_allowed_packet = 16M
18+
thread_stack = 192K
19+
thread_cache_size = 8
20+
21+
myisam-recover-options = BACKUP
22+
23+
general_log_file = /var/log/mysql/mysql.log
24+
general_log = 1
25+
log_error = /var/log/mysql/error.log

.vscode/settings.json

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"python.linting.pylintEnabled": true,
3+
"python.linting.enabled": true,
4+
"python.linting.pycodestyleEnabled": false,
5+
"python.linting.flake8Enabled": true,
6+
"python.terminal.activateEnvironment": false,
7+
"python.formatting.autopep8Path": "/home/gitpod/.pyenv/shims/autopep8",
8+
"python.linting.flake8Path": "/home/gitpod/.pyenv/shims/flake8",
9+
"cornflakes.linter.executablePath": "/home/gitpod/.pyenv/shims/flake8",
10+
"files.exclude": {
11+
"**/.DS_Store": true,
12+
"**/.git": true,
13+
"**/.github": true,
14+
"**/.gitp*": true,
15+
"**/.hg": true,
16+
"**/.svn": true,
17+
"**/.vscode": true,
18+
"**/core.Microsoft*": true,
19+
"**/core.mongo*": true,
20+
"**/core.python*": true,
21+
"**/CVS": true
22+
},
23+
"files.autoSave": "off",
24+
"workbench.colorTheme": "Visual Studio Dark",
25+
"editor.defaultFormatter": "HookyQR.beautify"
26+
}

.vscode/start_mysql.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# this script is intended to be called from .bashrc
4+
# This is a workaround for not having something like supervisord
5+
6+
if [ ! -e /var/run/mysqld/gitpod-init.lock ]
7+
then
8+
touch /var/run/mysqld/gitpod-init.lock
9+
10+
# initialize database structures on disk, if needed
11+
[ ! -d /workspace/mysql ] && mysqld --initialize-insecure
12+
13+
# launch database, if not running
14+
[ ! -e /var/run/mysqld/mysqld.pid ] && mysqld --daemonize
15+
16+
rm /var/run/mysqld/gitpod-init.lock
17+
fi

.vscode/uptime.sh

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
3+
# Pings the webhook so that we can gather
4+
# basic usage stats. No personally identifiable
5+
# data is captured here, and it is impossible to
6+
# identify an individual user from the captured data.
7+
# Matt Rudge, April 2021
8+
9+
UUID=$(cat /proc/sys/kernel/random/uuid)
10+
URL=https://1xthkmzwg3.execute-api.eu-west-1.amazonaws.com/prod/lrsapi/
11+
API_KEY=jceBCdeGZP9RDeUNCfM4jIQ39Cx0jtG51QgcwDwc
12+
VERB="started"
13+
14+
clear
15+
16+
while true; do
17+
18+
DATA="{\"activity_time\":\"$(date +%Y-%m-%dT%H:%M:%S).000Z\",\"actor\":\"${UUID}\",\"verb\":\"${VERB}\",\"activity_object\":\"Gitpod Workspace\",\"extra_data\":\"{}\"}"
19+
curl -s -X POST -H "x-api-key: ${API_KEY}" -d "${DATA}" ${URL} 1> /dev/null
20+
VERB="running"
21+
sleep 300
22+
23+
done

Procfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node index.js

0 commit comments

Comments
 (0)