Browse Source

fixed gunicorn errors, compose errors etc

master
Abhishek Balam 1 year ago
parent
commit
40bf815a0e
14 changed files with 1406 additions and 238 deletions
  1. 0
    33
      .docker/Dockerfile
  2. 0
    36
      .docker/Dockerfile1
  3. 0
    38
      .docker/Dockerfile2
  4. 0
    22
      .docker/install.sh
  5. 1
    1
      .gitignore
  6. 0
    25
      Dockerfile1
  7. 3
    8
      dev.sh
  8. 9
    8
      docker-compose.yml
  9. 0
    22
      install.sh
  10. 9
    9
      keeplinkin/__init__.py
  11. 0
    1
      keeplinkin/shortener.py
  12. 36
    29
      keeplinkin/static/js/index.js
  13. 1348
    0
      redis/conf/redis.conf
  14. 0
    6
      run1.sh

+ 0
- 33
.docker/Dockerfile View File

@@ -1,33 +0,0 @@
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"]

+ 0
- 36
.docker/Dockerfile1 View File

@@ -1,36 +0,0 @@
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

+ 0
- 38
.docker/Dockerfile2 View File

@@ -1,38 +0,0 @@
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

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

@@ -1,22 +0,0 @@
#! /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"

+ 1
- 1
.gitignore View File

@@ -1,4 +1,4 @@
venv
volumes/
redis/data/*
*.pyc
__pycache__

+ 0
- 25
Dockerfile1 View File

@@ -1,25 +0,0 @@
# Ubuntu
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 /application
COPY ./run /application
COPY requirements.txt /application
RUN mkdir -p /application/keeplinkin
ADD keeplinkin /application/keeplinkin

WORKDIR /application
RUN pip3 install -r requirements.txt

EXPOSE 8000

RUN chmod +x /application/run

#ENTRYPOINT /application/run
#RUN ls /application

+ 3
- 8
dev.sh View File

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

# export SITE_URL=http://localhost:5000
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
gunicorn -w 4 --bind 0.0.0.0:5000 keeplinkin:app

+ 9
- 8
docker-compose.yml View File

@@ -6,20 +6,18 @@ networks:

services:
app:
# build: .
image: 'keeplinkin_app:latest'
build: .
environment:
- FLASK_APP=keeplinkin
- FLASK_ENV=production
- APP_TOKEN=kamikaze
- FLASK_ENV=dev
- SECRET_KEY=dev
- ENV PYTHONPATH=/home/app
- ENV REDIS_HOST=redis
- SITE_URL=https://keeplink.in
- SITE_URL=http://localhost:5000
volumes:
- .:/home/app
ports:
- '5000:8000'
volumes:
- './src:/home/app'
depends_on:
- redis
networks:
@@ -27,7 +25,10 @@ services:
redis:
image: 'redis:latest'
volumes:
- './db:/usr/local/etc/redis'
- './redis/conf:/usr/local/etc/redis/'
- './redis/data:/data'
command:
- /usr/local/etc/redis/redis.conf
networks:
- keeplinkin
tty: true

+ 0
- 22
install.sh View File

@@ -1,22 +0,0 @@
#! /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"

+ 9
- 9
keeplinkin/__init__.py View File

@@ -6,7 +6,6 @@ from . import shortener

app = Flask(__name__)

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

@app.route('/')
@@ -24,15 +23,12 @@ def checkcustom(url):

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

if request.method == 'POST':
data=request.json
url=data['url']
type=data['type']
surl=data['surl']

short_url = "YoYoMaMa"

short_url = "test"
if(type=="default"):
short_url=shortener.default(url)
elif(type=="custom"):
@@ -44,8 +40,7 @@ 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
short_url=os.environ['SITE_URL']+'/'+short_url
print(url+ '<br>' + short_url);
return jsonify(
url=url,
@@ -59,7 +54,8 @@ def shorten():
return "Invalid URL!"
short_url=shortener.default(url)
print(short_url)
response='https://keeplink.in/'+short_url
# response='https://keeplink.in/'+short_url
response=os.environ['SITE_URL']+short_url
return response

@app.route('/<url>')
@@ -81,4 +77,8 @@ def resolve(url):
if __name__ == '__main__':
app.jinja_env.auto_reload = True
app.config['TEMPLATES_AUTO_RELOAD'] = True
app.run(debug=True)
app.config['SECRET_KEY'] = os.environ['SECRET_KEY']
if os.environ['FLASK_ENV'] == 'dev':
app.run(debug=True)
else:
app.run(debug=False)

+ 0
- 1
keeplinkin/shortener.py View File

@@ -4,7 +4,6 @@ from . import b62
from . import funnywords as fw

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)

+ 36
- 29
keeplinkin/static/js/index.js View File

@@ -1,3 +1,22 @@
$('#long_url').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$('#modalbtn').click();
return false;
}
});


$('#custom_url').keypress(function (e) {
var key = e.which;
if(key == 13) // the enter key code
{
$('#checkcustom').click();
return false;
}
});


function validURL(str) {
var regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
@@ -35,8 +54,9 @@ function stoppedTyping(obj) {
function prop(obj) {
console.log(obj.innerHTML);
if(obj.innerHTML=="Custom"){
console.log("herree")
$('#submitrequest').prop('disabled',true);
$('#custom_url').focus();
console.log("Custom");
$('#submitrequest').prop('disabled',true);
}
else{
$('#submitrequest').prop('disabled',false);
@@ -61,26 +81,7 @@ function CopyToClipboard(containerid) {
console.log('Oops, unable to copy');
alert('Unable to copy! Please copy manually...')
}

// Remove the selections - NOTE: Should use
// removeRange(range) when it is supported
window.getSelection().removeAllRanges();

// if (document.selection) {
// var range = document.body.createTextRange();
// range.moveToElementText(document.getElementById(containerid));
// range.select().createTextRange();
// document.execCommand("copy");
// }
// else if (window.getSelection) {
// var range = document.createRange();
// range.selectNode(document.getElementById(containerid));
// window.getSelection().addRange(range);
// document.execCommand("copy");
// alert("Link Copied!")
// }


}

$(document).ready(function(){
@@ -110,7 +111,6 @@ $(document).ready(function(){
}
}


$('.notif').hide();
$('#custom_url').val('https://keeplink.in/');
$(".navbar a, footer a[href='#home']").on('click', function(event) {
@@ -185,7 +185,9 @@ $(document).ready(function(){
c_url="/checkcustom/"+c_url
console.log(c_url)
$.ajax({url: c_url, success: function(result){
$.ajax({
url: c_url,
success:function(result){
console.log(result)
if(result=="0"){
$('#available').show();
@@ -194,7 +196,11 @@ $(document).ready(function(){
else{
$('#unavailable').show();
}
}});
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
});

$('#submitrequest').click(function(e){
@@ -209,7 +215,6 @@ $(document).ready(function(){
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
type = $(e.target).attr('id');
});
console.log("Url:"+l_url+"\nType:"+type+"\nCustom Url:"+ c_url);
@@ -223,15 +228,17 @@ $(document).ready(function(){
url: '/shorten/',
data: JSON.stringify(obj),
success:function(data) {
var shurl='/'+data.surl;
console.log(data);
$('#status').modal('show');
$('#ourl').html(data.url);
$('#ourl').attr('href',data.url);
$('#surl').html('https://keeplink.in'+shurl);
$('#surl').attr('href',shurl);
$('#surl').html(data.surl);
$('#surl').attr('href',data.surl);
$('#long_url').val("");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
},
dataType: 'json',
contentType: "application/json"
});

+ 1348
- 0
redis/conf/redis.conf
File diff suppressed because it is too large
View File


+ 0
- 6
run1.sh View File

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

set -e
export PYTHONPATH=/home/app
cd /home/app
bash -c 'exec gunicorn -w 4 -b 0.0.0.0:8000 keeplinkin:app'

Loading…
Cancel
Save