Browse Source

docker added

master
Abhishek Balam 1 year ago
parent
commit
bb333660cf
56 changed files with 257 additions and 62 deletions
  1. 33
    0
      .docker/Dockerfile
  2. 36
    0
      .docker/Dockerfile1
  3. 38
    0
      .docker/Dockerfile2
  4. 22
    0
      .docker/install.sh
  5. 0
    2
      .gitattributes
  6. 28
    0
      Dockerfile
  7. 0
    1
      Procfile
  8. 17
    0
      dev.sh
  9. 21
    0
      docker-compose.yml
  10. 22
    0
      install.sh
  11. 8
    9
      keeplinkin/__init__.py
  12. 13
    20
      keeplinkin/b62.py
  13. 3
    8
      keeplinkin/funnywords.py
  14. 8
    20
      keeplinkin/shortener.py
  15. 0
    0
      keeplinkin/static/css/main.css
  16. 0
    0
      keeplinkin/static/images/favicon.png
  17. 0
    0
      keeplinkin/static/js/clipboard.js-master/.babelrc
  18. 0
    0
      keeplinkin/static/js/clipboard.js-master/.editorconfig
  19. 0
    0
      keeplinkin/static/js/clipboard.js-master/.github/issue_template.md
  20. 0
    0
      keeplinkin/static/js/clipboard.js-master/.gitignore
  21. 0
    0
      keeplinkin/static/js/clipboard.js-master/.npmignore
  22. 0
    0
      keeplinkin/static/js/clipboard.js-master/.travis.yml
  23. 0
    0
      keeplinkin/static/js/clipboard.js-master/bower.json
  24. 0
    0
      keeplinkin/static/js/clipboard.js-master/composer.json
  25. 0
    0
      keeplinkin/static/js/clipboard.js-master/contributing.md
  26. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/constructor-node.html
  27. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/constructor-nodelist.html
  28. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/constructor-selector.html
  29. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/function-target.html
  30. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/function-text.html
  31. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/target-div.html
  32. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/target-input.html
  33. 0
    0
      keeplinkin/static/js/clipboard.js-master/demo/target-textarea.html
  34. 0
    0
      keeplinkin/static/js/clipboard.js-master/dist/clipboard.js
  35. 0
    0
      keeplinkin/static/js/clipboard.js-master/dist/clipboard.min.js
  36. 0
    0
      keeplinkin/static/js/clipboard.js-master/karma.conf.js
  37. 0
    0
      keeplinkin/static/js/clipboard.js-master/package.js
  38. 0
    0
      keeplinkin/static/js/clipboard.js-master/package.json
  39. 0
    0
      keeplinkin/static/js/clipboard.js-master/readme.md
  40. 0
    0
      keeplinkin/static/js/clipboard.js-master/src/clipboard-action.js
  41. 0
    0
      keeplinkin/static/js/clipboard.js-master/src/clipboard.js
  42. 0
    0
      keeplinkin/static/js/clipboard.js-master/test/clipboard-action.js
  43. 0
    0
      keeplinkin/static/js/clipboard.js-master/test/clipboard.js
  44. 0
    0
      keeplinkin/static/js/clipboard.js-master/webpack.config.js
  45. 0
    0
      keeplinkin/static/js/clipboard.min.js
  46. 0
    0
      keeplinkin/static/js/index.js
  47. 0
    0
      keeplinkin/templates/index.html
  48. 0
    0
      keeplinkin/templates/layouts/about.html
  49. 0
    0
      keeplinkin/templates/layouts/banner.html
  50. 0
    0
      keeplinkin/templates/layouts/base.html
  51. 0
    0
      keeplinkin/templates/layouts/contact.html
  52. 0
    0
      keeplinkin/templates/layouts/modal.html
  53. 1
    0
      keeplinkin/wsgi.py
  54. 1
    1
      requirements.txt
  55. 6
    0
      run.sh
  56. 0
    1
      runtime.txt

+ 33
- 0
.docker/Dockerfile View File

@@ -0,0 +1,33 @@
FROM python:3.7-alpine

RUN apk add --update gcc libc-dev fortify-headers linux-headers && rm -rf /var/cache/apk/*

RUN mkdir -p /home/app

COPY dev.sh /home/app
COPY requirements.txt /home/app
COPY setup.py /home/app
COPY MANIFEST.in /home/app

RUN mkdir -p /home/app/keeplinkin
ADD keeplinkin /home/app/keeplinkin

WORKDIR /home/app

RUN pip install -r requirements.txt

ENV FLASK_APP=keeplinkin
ENV FLASK_ENV=production
ENV APP_TOKEN=
ENV SECRET_KEY=
ENV SITE_URL="https://keeplink.in"
ENV GUNICORN_WORKERS=4
ENV GUNICORN_BIND=0.0.0.0:8000

EXPOSE 8000

ENV PYTHONPATH=/home/app/keeplinkin

RUN gunicorn -w 4 -b 0.0.0.0:8000 keeplinkin:app
#ENTRYPOINT ["gunicorn"]
#CMD ["-w 4","-b","0.0.0.0:8000", "app:app"]

+ 36
- 0
.docker/Dockerfile1 View File

@@ -0,0 +1,36 @@
FROM python:3.7-alpine

RUN apk add --update gcc bash libc-dev fortify-headers linux-headers && rm -rf /var/cache/apk/*

RUN mkdir -p /home/app

COPY run.sh /home/app
COPY requirements.txt /home/app

RUN mkdir -p /home/app/keeplinkin
ADD keeplinkin /home/app/keeplinkin

WORKDIR /home/app

RUN pip install -r requirements.txt

ENV FLASK_APP=keeplinkin
ENV FLASK_ENV=production
ENV APP_TOKEN=
ENV SECRET_KEY=
ENV SITE_URL=https://keeplink.in

# ENV GUNICORN_WORKERS=4
# ENV GUNICORN_BIND=0.0.0.0:8000

EXPOSE 8000

ENV PYTHONPATH=/home/app/

RUN ls /home

RUN pwd

RUN chmod +x /home/app/run.sh

ENTRYPOINT $HOME/app/run.sh

+ 38
- 0
.docker/Dockerfile2 View File

@@ -0,0 +1,38 @@
FROM ubuntu:latest

MAINTAINER Abhishek Balam "[email protected]"

RUN apt update -y
RUN apt install -y python3-dev python3-pip python3-venv build-essential

RUN mkdir -p /home/app
#COPY dev.sh /home/app
#COPY setup.py /home/app
#COPY MANIFEST.in /home/app
COPY requirements.txt /home/app

RUN mkdir -p /home/app/keeplinkin
ADD keeplinkin /home/app/keeplinkin

WORKDIR /home/app
RUN python3 -m venv venv
RUN /bin/bash -c "source venv/bin/activate"

RUN pip3 install -r requirements.txt

ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

ENV FLASK_APP=keeplinkin
ENV FLASK_ENV=production
ENV APP_TOKEN=kamikaze
ENV SECRET_KEY=dev
ENV SITE_URL="https://keeplink.in"
ENV PYTHONPATH=/home/app

#ENV GUNICORN_WORKERS=4
#ENV GUNICORN_BIND=0.0.0.0:8000

EXPOSE 8000

ENTRYPOINT gunicorn -w 4 -b 0.0.0.0:8000 keeplinkin:app

+ 22
- 0
.docker/install.sh View File

@@ -0,0 +1,22 @@
#! /bin/bash

# Build Image
docker build -t keeplinkin:latest .

# Run Image
docker run -d --name keeplinkin -v $HOME/keeplinkin:/home/app -p 0.0.0.0:5000:8000 keeplinkin:latest

# Utils
# docker ps -aq # list
# docker stop $(docker ps -aq) # stop all
# docker rm $(docker ps -aq) # rm all cont.
# docker rmi $(docker images -q) # rm all images


# To Initalise Sqlite DB
# IMG_NAME=`docker inspect --format='{{.Name}}' $(docker ps -aq --no-trunc) | cut -c2-`

# echo $IMAGE_NAME
# docker exec -it rms_reg flask init-db

echo "Docker Container Setup successfully.\n The app is running in Port 5000"

+ 0
- 2
.gitattributes View File

@@ -1,2 +0,0 @@
templates/layouts/* linguist-documentation
* linguist-language=Python

+ 28
- 0
Dockerfile View File

@@ -0,0 +1,28 @@
FROM ubuntu:latest

MAINTAINER Abhishek Balam "[email protected]"

RUN apt update -y
RUN apt install -y python3-dev python3-pip python3-venv build-essential
ENV LC_ALL=C.UTF-8
ENV LANG=C.UTF-8

RUN mkdir -p /app
COPY ./run.sh /app
COPY requirements.txt /app
RUN mkdir -p /app/keeplinkin
ADD keeplinkin /app/keeplinkin

WORKDIR /app
RUN pip3 install -r requirements.txt

EXPOSE 8000

ENV PYTHONPATH=/app
ENV REDIS_HOST=redis

RUN chmod +x /app/run.sh

ENTRYPOINT /app/run.sh

RUN ls /app

+ 0
- 1
Procfile View File

@@ -1 +0,0 @@
web: gunicorn app:app --log-file -

+ 17
- 0
dev.sh View File

@@ -0,0 +1,17 @@
export FLASK_APP=keeplinkin
export FLASK_ENV=dev
export APP_TOKEN=kamkaze

# export SITE_URL=http://localhost:5000
export SECRET_KEY=

### DB Commands
## For fresh DB Initilization only
# flask init-db

### For running the application
## Development Server
# flask run

## Production Server
gunicorn -w 4 --bind 0.0.0.0:8000 keeplinkin:app

+ 21
- 0
docker-compose.yml View File

@@ -0,0 +1,21 @@
version: '2'

services:
app:
build: .
environment:
- FLASK_APP=keeplinkin
- FLASK_ENV=production
- APP_TOKEN=
- SECRET_KEY=dev
- SITE_URL=https://keeplink.in
ports:
- '5000:8000'
volumes:
- './volumes/app:/app'
depends_on:
- redis
redis:
image: redis
volumes:
- './volumes/redis:/usr/local/etc/redis'

+ 22
- 0
install.sh View File

@@ -0,0 +1,22 @@
#! /bin/bash

# Build Image
docker build -t keeplinkin .

# Run Image
docker run -d --name keeplinkin -v $HOME/keeplinkin:/home/app -p 0.0.0.0:5000:8000 keeplinkin

# Utils
# docker ps -aq # list
# docker stop $(docker ps -aq) # stop all
# docker rm $(docker ps -aq) # rm all cont.
# docker rmi $(docker images -q) # rm all images


# To Initalise Sqlite DB
# IMG_NAME=`docker inspect --format='{{.Name}}' $(docker ps -aq --no-trunc) | cut -c2-`

# echo $IMAGE_NAME
# docker exec -it rms_reg flask init-db

echo "Docker Container Setup successfully.\n The app is running in Port 5000"

app.py → keeplinkin/__init__.py View File

@@ -1,16 +1,16 @@
import os
from flask import Flask, render_template, request, redirect, jsonify
import shortener
import redis
from scout_apm.flask import ScoutApm
import validators
from . import shortener

app = Flask(__name__)

ScoutApm(app)

db=redis.from_url(os.environ['REDISCLOUD_URL'])
# db=redis.Redis(host='localhost', port=6379, password='')
# db=redis.from_url(os.environ['REDIS_URL'])
db=redis.Redis(host=os.environ['REDIS_HOST'], port=6379)

@app.route('/')
def main():
@@ -25,8 +25,6 @@ def checkcustom(url):
else:
return "0"



@app.route('/shorten/', methods=['POST','GET'])
def shorten():

@@ -49,7 +47,6 @@ def shorten():
short_url=shortener.semantic(url)
else:
return "Wrong Type"

# short_url = 'shortened url: %s \n ' % short_url
# long_url = 'Orginal url: %s \n' % url
print(url+ '<br>' + short_url);
@@ -57,7 +54,6 @@ def shorten():
url=url,
surl=short_url
)

else:
url=request.args.get("url")
url=url.replace('"', '')
@@ -71,7 +67,10 @@ def shorten():

@app.route('/<url>')
def resolve(url):
long_url=shortener.decode(url)
try:
long_url=shortener.decode(url)
except Exception as e:
print(str(e))
if(long_url):
long_url=long_url.replace('"','')
if ("http://" not in long_url):
@@ -86,4 +85,4 @@ if __name__ == '__main__':
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.config['SCOUT_NAME'] = "Keeplinkin"
app.run(debug=True)
app.run(debug=True)

b62.py → keeplinkin/b62.py View File

@@ -1,13 +1,11 @@

BASE62 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
BASE62 = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'

def encode(num, alphabet=BASE62):
"""Encode a positive number in Base X

'''Encode a positive number in Base X
Arguments:
- `num`: The number to encode
- `alphabet`: The alphabet to use for encoding
"""
'''
if num == 0:
return alphabet[0]
arr = []
@@ -19,32 +17,27 @@ def encode(num, alphabet=BASE62):
return ''.join(arr)

def decode(string, alphabet=BASE62):
"""Decode a Base X encoded string into the number

'''Decode a Base X encoded string into the number
Arguments:
- `string`: The encoded string
- `alphabet`: The alphabet to use for encoding
"""
'''
base = len(alphabet)
strlen = len(string)
num = 0

idx = 0
for char in string:
power = (strlen - (idx + 1))
num += alphabet.index(char) * (base ** power)
idx += 1

return num

def main():
num=10000
print(num)
print(encode(num))
# print(type(encode(num)))
# print(type(decode(encode(num))))


if __name__ == '__main__':
main()
# def main():
# num=10000
# print(num)
# print(encode(num))
# print(type(encode(num)))
# print(type(decode(encode(num))))

# if __name__ == '__main__':
# main()

funnywords.py → keeplinkin/funnywords.py View File

@@ -8,10 +8,8 @@ def gen_word(min, max):
syllables = min + int(random.random() * (max - min))
for i in range(0, syllables):
word += gen_syllable()
return word.capitalize()


def gen_syllable():
ran = random.random()
if ran < 0.333:
@@ -20,16 +18,13 @@ def gen_syllable():
return word_part('c') + word_part('v')
return word_part('c') + word_part('v') + word_part('c')


def word_part(type):
if type is 'c':
return random.sample([ch for ch in list(string.lowercase) if ch not in vowels], 1)[0]
return random.sample([ch for ch in list(string.ascii_lowercase) if ch not in vowels], 1)[0]
if type is 'v':
return random.sample(vowels, 1)[0]



# Testing
# for i in range(0, 1):
# print gen_word(2,4)

print gen_word(2,4)
# print gen_word(2,4)

shortener.py → keeplinkin/shortener.py View File

@@ -1,58 +1,46 @@
import os
import redis
import b62
import funnywords as fw
from . import b62
from . import funnywords as fw

# For Remote DB
db=redis.from_url(os.environ['REDISCLOUD_URL'])

# For Local DB
# db=redis.Redis(host='localhost', port=6379, password='')
db=redis.Redis(host=os.environ['REDIS_HOST'], port=6379)
# db=redis.from_url(os.environ['REDIS_URL'])

def default(l_url):
score=(db.zcard('default')+1)
if(score<10000):
score=score+10000

s_url=b62.encode(score)
# db.zadd('default',l_url,score)
db.execute_command('ZADD', 'default', 'NX', score, l_url)
return s_url

def custom(l_url, c_url):
status=db.hexists('custom',c_url)

if(status==0):
status=db.hsetnx('custom', c_url, l_url)
return c_url
def semantic(l_url):

c_url=fw.gen_word(2,4)

status=db.hexists('custom',c_url)

if(status==0):
status=db.hsetnx('custom', c_url, l_url)
else:
semantic(l_url)
return c_url

def decode(s_url):
status=db.hexists('custom',s_url)
if(status==1):
l_url=db.hget('custom', s_url)
l_url=l_url.decode('utf-8')
else:
try:
key=b62.decode(s_url)
l_url=db.zrangebyscore('default',key,key)
l_url=''.join(l_url)
except:
l_url=l_url[0].decode('utf-8')
except Exception as e:
# print('Error in urldecode:'+str(e))
l_url=False

return l_url

static/css/main.css → keeplinkin/static/css/main.css View File


static/images/favicon.png → keeplinkin/static/images/favicon.png View File


static/js/clipboard.js-master/.babelrc → keeplinkin/static/js/clipboard.js-master/.babelrc View File


static/js/clipboard.js-master/.editorconfig → keeplinkin/static/js/clipboard.js-master/.editorconfig View File


static/js/clipboard.js-master/.github/issue_template.md → keeplinkin/static/js/clipboard.js-master/.github/issue_template.md View File


static/js/clipboard.js-master/.gitignore → keeplinkin/static/js/clipboard.js-master/.gitignore View File


static/js/clipboard.js-master/.npmignore → keeplinkin/static/js/clipboard.js-master/.npmignore View File


static/js/clipboard.js-master/.travis.yml → keeplinkin/static/js/clipboard.js-master/.travis.yml View File


static/js/clipboard.js-master/bower.json → keeplinkin/static/js/clipboard.js-master/bower.json View File


static/js/clipboard.js-master/composer.json → keeplinkin/static/js/clipboard.js-master/composer.json View File


static/js/clipboard.js-master/contributing.md → keeplinkin/static/js/clipboard.js-master/contributing.md View File


static/js/clipboard.js-master/demo/constructor-node.html → keeplinkin/static/js/clipboard.js-master/demo/constructor-node.html View File


static/js/clipboard.js-master/demo/constructor-nodelist.html → keeplinkin/static/js/clipboard.js-master/demo/constructor-nodelist.html View File


static/js/clipboard.js-master/demo/constructor-selector.html → keeplinkin/static/js/clipboard.js-master/demo/constructor-selector.html View File


static/js/clipboard.js-master/demo/function-target.html → keeplinkin/static/js/clipboard.js-master/demo/function-target.html View File


static/js/clipboard.js-master/demo/function-text.html → keeplinkin/static/js/clipboard.js-master/demo/function-text.html View File


static/js/clipboard.js-master/demo/target-div.html → keeplinkin/static/js/clipboard.js-master/demo/target-div.html View File


static/js/clipboard.js-master/demo/target-input.html → keeplinkin/static/js/clipboard.js-master/demo/target-input.html View File


static/js/clipboard.js-master/demo/target-textarea.html → keeplinkin/static/js/clipboard.js-master/demo/target-textarea.html View File


static/js/clipboard.js-master/dist/clipboard.js → keeplinkin/static/js/clipboard.js-master/dist/clipboard.js View File


static/js/clipboard.js-master/dist/clipboard.min.js → keeplinkin/static/js/clipboard.js-master/dist/clipboard.min.js View File


static/js/clipboard.js-master/karma.conf.js → keeplinkin/static/js/clipboard.js-master/karma.conf.js View File


static/js/clipboard.js-master/package.js → keeplinkin/static/js/clipboard.js-master/package.js View File


static/js/clipboard.js-master/package.json → keeplinkin/static/js/clipboard.js-master/package.json View File


static/js/clipboard.js-master/readme.md → keeplinkin/static/js/clipboard.js-master/readme.md View File


static/js/clipboard.js-master/src/clipboard-action.js → keeplinkin/static/js/clipboard.js-master/src/clipboard-action.js View File


static/js/clipboard.js-master/src/clipboard.js → keeplinkin/static/js/clipboard.js-master/src/clipboard.js View File


static/js/clipboard.js-master/test/clipboard-action.js → keeplinkin/static/js/clipboard.js-master/test/clipboard-action.js View File


static/js/clipboard.js-master/test/clipboard.js → keeplinkin/static/js/clipboard.js-master/test/clipboard.js View File


static/js/clipboard.js-master/webpack.config.js → keeplinkin/static/js/clipboard.js-master/webpack.config.js View File


static/js/clipboard.min.js → keeplinkin/static/js/clipboard.min.js View File


static/js/index.js → keeplinkin/static/js/index.js View File


templates/index.html → keeplinkin/templates/index.html View File


templates/layouts/about.html → keeplinkin/templates/layouts/about.html View File


templates/layouts/banner.html → keeplinkin/templates/layouts/banner.html View File


templates/layouts/base.html → keeplinkin/templates/layouts/base.html View File


templates/layouts/contact.html → keeplinkin/templates/layouts/contact.html View File


templates/layouts/modal.html → keeplinkin/templates/layouts/modal.html View File


+ 1
- 0
keeplinkin/wsgi.py View File

@@ -0,0 +1 @@
from . import app

+ 1
- 1
requirements.txt View File

@@ -17,4 +17,4 @@ scout-apm==1.1.8
six==1.11.0
urllib3==1.23
validators==0.12.2
Werkzeug==0.14.1
Werkzeug==0.14.1

+ 6
- 0
run.sh View File

@@ -0,0 +1,6 @@
#! /bin/bash

set -e

cd /app
exec gunicorn -w 4 -b 0.0.0.0:8000 keeplinkin:app

+ 0
- 1
runtime.txt View File

@@ -1 +0,0 @@
python-2.7.15

Loading…
Cancel
Save