Posts

Showing posts from November, 2020

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Error cause: Install packages on debian jessie with pip python 3.8.  Fix: Install with pip python 3.6 and run "python3.6 -m pip install <package>". Install python 3.6: https://www.rosehosting.com/blog/how-to-install-python-3-6-4-on-debian-9/

Using environment variables in your code with docker-compose.yml

Image
In this blog, you will learn to access environment variables in your code with docker-compose.yml. This blog assumes that you are using python .  To start off, if you are curious about how you can use environment variables in your code from docker-compose file, basically it takes variable assigned to variables under the "environment" section in the docker-compose file. A picture below will demonstrate how it works. 1 - Docker Compose where you initialize the environment variable 2 - The code where you use the environment variable 3 - The output Method 1: Using .env This is probably one of the most common method because it is easy to use. However, if you use this method, you will need to remember to add this file into .gitignore if you are storing private credentials. 1) To start with, create your .env file and insert your environment variables like so: KEY=VALUE 2) Next, add this line of code below the service that would be using the environment variables in your .env file. ...

How to push codes to github

 1) Go to command prompt by pressing on Windows Key and type "cmd" 2) Go to your folder which you want to push your code to github by doing "cd directory/to/app 3) Do " git init " 4) Do " git add ." 5) Do " git commit -m "Commit message " 6) Do " git  branch -M main " 6) Do "git remote add origin <github link>"  example: "git remote add https://github.com/Cawleeflower/tutorial-env.git" 7) Do "git push -u origin main" Errors that may occur: 1)  fatal: unable to access 'https://github.com/<github-name>/<repo-name>.git/': The requested URL returned error: 403 For this error, you'll just need to add "<github-name>@" preceding the 'https' and 'github.com' like so: "git remote set-url origin "https://<github-name>@github.com/<github-name>/<repo-name>.git/' Please note that this is just a workaround. 2)  error:...

How to add environment variables into Heroku container

Image
 Method 1: Using .env file  NOTE: Please add your .env file into .gitignore to not make the file visiblein github. Before we start, please make sure you have ran ' heroku scale worker=1 -a (app) ' in your app.  1) Create an .env file and add your environment variable like so: your-environment-variable=123 2) In your code, import load_dotenv from dotenv like so: import os from dotenv import load_dotenv load_dotenv() test-env = os.getenv('your-environment-variable')  print(test-env)  Note: Please make sure you have requirements.txt present by doing 'pip freeze > requirements.txt' 3) Create your dockerfile FROM python:latest WORKDIR / COPY . . RUN pip install -r requirements.txt CMD [ "python", "test.py" ] 4) Run ' heroku container:push worker -a (app name) ' 5) Run ' heroku container:release worker -a (app name) ' 6) Wait for 10-20 seconds... 7) You can test if your app is working by running ' heroku logs -a (app name)...

How to deploy discord bot on heroku with docker

This guide assumes that you have created your own discord bot, installed docker, and have a heroku app ready to be pushed. 1) Build your dockerfile: FROM python:latest WORKDIR / COPY . . ARG BOT_TOKEN ENV BOT_TOKEN=$BOT_TOKEN RUN pip install -r requirements.txt CMD [ "python", "bot.py" ] 3) Add 'Procfile' in the same directory and add this command in it. ' worker:   python (script name).py' 3) Build your discord bot in docker locally by running this command 'docker build --build-arg (environment-variable-for-token)=(token) -t (image name) (current directory)' example: 'docker build --build-arg BOT_TOKEN=token -t first_bot .' 4) Run ' heroku scale worker=1' 5) Next, tag the image built to the heroku like so 'docker tag (image id) registry.heroku.com/(your-app-name)/worker' 6) After that, push the image to heroku  'docker push registry.heroku.com/(your-app-name)/worker' 7) Finally, release the image   'heroku...

How to run pip python 3.6 on debian jessie

NOTE: This is not a solution but just a workaround. If you have installed pip in your debian console and did "pip3 --version", you will meet this message     " pip 1.5.6 from /usr/lib/python3/dist-packages (python 3.4)" And this version of pip doesn't allow you to install a lot of packages from python, but there is a workaround. Before we get started, this blog assumes that you have installed python and pip. If you haven't, links down below for installing them. (Note that python 3.6.4 is used) To start running pip python 3.6, Just follow this steps: Step 1: Run "python3.6 -m pip install virtualenv" Note: Please don't use "pip3 install virtualenv" , or you might run into an error (NameError: name 'ModuleNotFoundError' is not defined) Step 2: Run "virtualenv -p python3 venv"   Step 3 : Run ".venv/bin/activate" Reference: Virtualenv commands: https://stackoverflow.com/questions/42044346/reinstall-python-2-7-12...