From 10d730c6b00ee59a65fff8dcab55a4b67eea651a Mon Sep 17 00:00:00 2001 From: p0wen <41102262+p0wen@users.noreply.github.com> Date: Tue, 19 May 2020 06:24:44 +0200 Subject: [PATCH] Initial commit --- .gitpod.dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ .gitpod.yml | 12 ++++++++++++ .theia/client.cnf | 10 ++++++++++ .theia/init_tasks.sh | 23 +++++++++++++++++++++++ .theia/launch.json | 14 ++++++++++++++ .theia/mysql.cnf | 25 +++++++++++++++++++++++++ .theia/settings.json | 20 ++++++++++++++++++++ .theia/snippets.json | 7 +++++++ .theia/start_mysql.sh | 17 +++++++++++++++++ README.md | 39 +++++++++++++++++++++++++++++++++++++++ 10 files changed, 210 insertions(+) create mode 100644 .gitpod.dockerfile create mode 100644 .gitpod.yml create mode 100644 .theia/client.cnf create mode 100644 .theia/init_tasks.sh create mode 100644 .theia/launch.json create mode 100644 .theia/mysql.cnf create mode 100644 .theia/settings.json create mode 100644 .theia/snippets.json create mode 100644 .theia/start_mysql.sh create mode 100644 README.md diff --git a/.gitpod.dockerfile b/.gitpod.dockerfile new file mode 100644 index 0000000..cca4864 --- /dev/null +++ b/.gitpod.dockerfile @@ -0,0 +1,43 @@ +FROM gitpod/workspace-full + +USER root +# Setup Heroku CLI +RUN curl https://cli-assets.heroku.com/install.sh | sh + +# Setup MongoDB and MySQL +RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4 && \ + echo "deb http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-4.0.list && \ + apt-get update -y && \ + touch /etc/init.d/mongod && \ + apt-get -y install mongodb-org mongodb-org-server -y && \ + apt-get update -y && \ + apt-get -y install links && \ + apt-get install -y mysql-server && \ + apt-get clean && rm -rf /var/cache/apt/* /var/lib/apt/lists/* /tmp/* && \ + mkdir /var/run/mysqld && \ + 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/ && \ + pip3 install flake8 flake8-flask flake8-django + +# Create our own config files + +COPY .theia/mysql.cnf /etc/mysql/mysql.conf.d/mysqld.cnf + +COPY .theia/client.cnf /etc/mysql/mysql.conf.d/client.cnf + +COPY .theia/start_mysql.sh /etc/mysql/mysql-bashrc-launch.sh + +USER gitpod + +# Start MySQL when we log in + +RUN echo ". /etc/mysql/mysql-bashrc-launch.sh" >> ~/.bashrc + +# Local environment variables +# C9USER is temporary to allow the MySQL Gist to run +ENV C9_USER="gitpod" +ENV PORT="8080" +ENV IP="0.0.0.0" +ENV C9_HOSTNAME="localhost" + +USER root +# Switch back to root to allow IDE to load diff --git a/.gitpod.yml b/.gitpod.yml new file mode 100644 index 0000000..1504aea --- /dev/null +++ b/.gitpod.yml @@ -0,0 +1,12 @@ +image: + file: .gitpod.dockerfile +tasks: + - init: . ${GITPOD_REPO_ROOT}/.theia/init_tasks.sh +vscode: + extensions: + - ms-python.python@2019.8.30787:TnGEOx35GXMhyKLjDGz9Aw== + - formulahendry.auto-close-tag@0.5.6:oZ/8R2VhZEhkHsoeO57hSw== + - mkaufman.HTMLHint@0.6.0:TdNYbCmjW8N3yiaPW4/adg== + - eventyret.bootstrap-4-cdn-snippet@1.6.0:AtNd6GnbCYVpmUkOaFXs3A== + - esbenp.prettier-vscode@4.3.0:jkl8NYpF/GzsahVpjggK0Q== + - kevinglasson.cornflakes-linter@0.4.0:Sgfmpf9YWoF5/BDJu2xn0w== diff --git a/.theia/client.cnf b/.theia/client.cnf new file mode 100644 index 0000000..12dcd7a --- /dev/null +++ b/.theia/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/.theia/init_tasks.sh b/.theia/init_tasks.sh new file mode 100644 index 0000000..1cd2423 --- /dev/null +++ b/.theia/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 ${C9_USER} user in MySQL" +mysql -e "CREATE USER '${C9_USER}'@'%' IDENTIFIED BY '';" -u root +echo "Granting privileges" +mysql -e "GRANT ALL PRIVILEGES ON *.* TO '${C9_USER}'@'%' WITH GRANT OPTION;" -u root +echo "Creating .sqliterc file" +echo ".headers on" > ~/.sqliterc +echo ".mode column" >> ~/.sqliterc +echo "Adding run aliases" +echo 'alias run="python3 $GITPOD_REPO_ROOT/manage.py runserver 0.0.0.0:8000"' >> ~/.bashrc +echo 'alias python=python3' >> ~/.bashrc +echo 'alias pip=pip3' >> ~/.bashrc +echo "Done" +source ~/.bashrc diff --git a/.theia/launch.json b/.theia/launch.json new file mode 100644 index 0000000..d9e387c --- /dev/null +++ b/.theia/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/.theia/mysql.cnf b/.theia/mysql.cnf new file mode 100644 index 0000000..1fd3264 --- /dev/null +++ b/.theia/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/.theia/settings.json b/.theia/settings.json new file mode 100644 index 0000000..292fe09 --- /dev/null +++ b/.theia/settings.json @@ -0,0 +1,20 @@ +{ + "python.linting.pylintEnabled": false, + "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": { + "**/.git": true, + "**/.gitp*": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/.theia": true, + }, + "emmet.extensionsPath": ".theia" +} diff --git a/.theia/snippets.json b/.theia/snippets.json new file mode 100644 index 0000000..469afc1 --- /dev/null +++ b/.theia/snippets.json @@ -0,0 +1,7 @@ +{ + "html": { + "snippets": { + "form": "form>input>input:submit[value=\"Submit\"]" + } + } +} diff --git a/.theia/start_mysql.sh b/.theia/start_mysql.sh new file mode 100644 index 0000000..1872562 --- /dev/null +++ b/.theia/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/README.md b/README.md new file mode 100644 index 0000000..d668594 --- /dev/null +++ b/README.md @@ -0,0 +1,39 @@ + + +Welcome USER_NAME, + +This is the Code Institute student template for Gitpod. We have preinstalled all of the tools you need to get started. You can safely delete this README.md file, or change it for your own project. + +## 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 backend lessons. + +## Updates Since The Instructional Video + +We continually tweak and adjust this template to help give you the best experience. Here are the updates since the original video was made: + +**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. + +-------- + +Happy coding!