From 4f4a194cad12430921eac783ad9122bc4fd2aba6 Mon Sep 17 00:00:00 2001 From: Utree Date: Fri, 7 Dec 2018 19:35:46 +0900 Subject: [PATCH] =?UTF-8?q?SSH=20=E3=83=9D=E3=83=BC=E3=83=88=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=AF=E3=83=BC=E3=83=87=E3=82=A3=E3=83=B3=E3=82=B0?= =?UTF-8?q?=E7=94=A8=E3=82=A2=E3=83=97=E3=83=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 - Procfile | 2 +- Procfile.windows | 2 +- README.md | 43 ++--------- app.json | 18 ++--- gettingstarted/__init__.py | 0 gettingstarted/settings.py | 119 ------------------------------- gettingstarted/static/humans.txt | 0 gettingstarted/urls.py | 21 ------ gettingstarted/wsgi.py | 16 ----- hello/__init__.py | 0 hello/admin.py | 3 - hello/migrations/0001_initial.py | 23 ------ hello/migrations/__init__.py | 0 hello/models.py | 5 -- hello/static/lang-logo.png | Bin 2217 -> 0 bytes hello/templates/base.html | 83 --------------------- hello/templates/db.html | 21 ------ hello/templates/index.html | 58 --------------- hello/tests.py | 19 ----- hello/views.py | 19 ----- manage.py | 16 +++-- requirements.txt | 4 +- 23 files changed, 29 insertions(+), 446 deletions(-) delete mode 100644 gettingstarted/__init__.py delete mode 100644 gettingstarted/settings.py delete mode 100644 gettingstarted/static/humans.txt delete mode 100644 gettingstarted/urls.py delete mode 100644 gettingstarted/wsgi.py delete mode 100644 hello/__init__.py delete mode 100644 hello/admin.py delete mode 100644 hello/migrations/0001_initial.py delete mode 100644 hello/migrations/__init__.py delete mode 100644 hello/models.py delete mode 100644 hello/static/lang-logo.png delete mode 100644 hello/templates/base.html delete mode 100644 hello/templates/db.html delete mode 100644 hello/templates/index.html delete mode 100644 hello/tests.py delete mode 100644 hello/views.py diff --git a/.gitignore b/.gitignore index 4875ad398..dbbaf135b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ venv *.pyc -staticfiles .env -db.sqlite3 -getting-started/* \ No newline at end of file diff --git a/Procfile b/Procfile index 47a27c07f..0918754c4 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: gunicorn gettingstarted.wsgi --log-file - +web: python manage.py $PORT diff --git a/Procfile.windows b/Procfile.windows index 69789e554..16c6fb476 100644 --- a/Procfile.windows +++ b/Procfile.windows @@ -1 +1 @@ -web: python manage.py runserver 0.0.0.0:5000 +web: web: python manage.py 5000 diff --git a/README.md b/README.md index 8cbdb7f82..e26e6f709 100644 --- a/README.md +++ b/README.md @@ -1,45 +1,16 @@ -# Python: Getting Started +# PythonでSSH Tunnel (ポートフォワーディング) -A barebones Django app, which can easily be deployed to Heroku. - -This application supports the [Getting Started with Python on Heroku](https://devcenter.heroku.com/articles/getting-started-with-python) article - check it out. - -## Running Locally - -Make sure you have Python 3.7 [installed locally](http://install.python-guide.org). To push to Heroku, you'll need to install the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli), as well as [Postgres](https://devcenter.heroku.com/articles/heroku-postgresql#local-setup). - -```sh -$ git clone https://github.com/heroku/python-getting-started.git +## 使い方 +``` +$ git clone https://github.com/Utree/python-getting-started.git $ cd python-getting-started - -$ python3 -m venv getting-started -$ pip install -r requirements.txt - -$ createdb python_getting_started - -$ python manage.py migrate -$ python manage.py collectstatic - -$ heroku local ``` -Your app should now be running on [localhost:5000](http://localhost:5000/). - -## Deploying to Heroku +適宜、manage.py のIPアドレス、ユーザー名、パスワード、ポート番号は変更してください。 -```sh +``` $ heroku create $ git push heroku master - -$ heroku run python manage.py migrate +$ heroku ps:scale web=1 $ heroku open ``` -or - -[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy) - -## Documentation - -For more information about using Python on Heroku, see these Dev Center articles: - -- [Python on Heroku](https://devcenter.heroku.com/categories/python) diff --git a/app.json b/app.json index 8721c4994..f0ffbc6b4 100644 --- a/app.json +++ b/app.json @@ -1,21 +1,21 @@ { - "name": "Start on Heroku: Python", - "description": "A barebones Python app, which can easily be deployed to Heroku.", + "name": "PythonでSSHポートフォワーディング", + "description": "PythonでSSHポートフォワーディング(Heroku用)", "image": "heroku/python", - "repository": "https://github.com/heroku/python-getting-started", - "keywords": ["python", "django" ], - "addons": [ "heroku-postgresql" ], + "repository": "https://github.com/Utree/python-getting-started", + "keywords": ["python"], + "addons": [], "env": { "SECRET_KEY": { - "description": "The secret key for the Django application.", - "generator": "secret" + "description": "", + "generator": "" } }, "environments": { "test": { "scripts": { - "test-setup": "python manage.py collectstatic --noinput", - "test": "python manage.py test" + "test-setup": "python manage.py $PORT", + "test": "python manage.py $PORT" } } } diff --git a/gettingstarted/__init__.py b/gettingstarted/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/gettingstarted/settings.py b/gettingstarted/settings.py deleted file mode 100644 index 9ea552a0c..000000000 --- a/gettingstarted/settings.py +++ /dev/null @@ -1,119 +0,0 @@ -""" -Django settings for gettingstarted project. - -Generated by 'django-admin startproject' using Django 2.0. - -For more information on this file, see -https://docs.djangoproject.com/en/2.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.0/ref/settings/ -""" - -import os -import django_heroku - - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = "CHANGE_ME!!!! (P.S. the SECRET_KEY environment variable will be used, if set, instead)." - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = [ - "django.contrib.admin", - "django.contrib.auth", - "django.contrib.contenttypes", - "django.contrib.sessions", - "django.contrib.messages", - "django.contrib.staticfiles", - "hello", -] - -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "django.contrib.messages.middleware.MessageMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -ROOT_URLCONF = "gettingstarted.urls" - -TEMPLATES = [ - { - "BACKEND": "django.template.backends.django.DjangoTemplates", - "DIRS": [], - "APP_DIRS": True, - "OPTIONS": { - "context_processors": [ - "django.template.context_processors.debug", - "django.template.context_processors.request", - "django.contrib.auth.context_processors.auth", - "django.contrib.messages.context_processors.messages", - ] - }, - } -] - -WSGI_APPLICATION = "gettingstarted.wsgi.application" - - -# Database -# https://docs.djangoproject.com/en/2.0/ref/settings/#databases - -DATABASES = { - "default": { - "ENGINE" : "django.db.backends.sqlite3", - "NAME": os.path.join(BASE_DIR, "db.sqlite3") - } -} - -# Password validation -# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators - -AUTH_PASSWORD_VALIDATORS = [ - { - "NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator" - }, - {"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator"}, - {"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator"}, - {"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator"}, -] - - -# Internationalization -# https://docs.djangoproject.com/en/2.0/topics/i18n/ - -LANGUAGE_CODE = "en-us" - -TIME_ZONE = "UTC" - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/2.0/howto/static-files/ - -STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') -STATIC_URL = "/static/" - -django_heroku.settings(locals()) diff --git a/gettingstarted/static/humans.txt b/gettingstarted/static/humans.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/gettingstarted/urls.py b/gettingstarted/urls.py deleted file mode 100644 index 13b759582..000000000 --- a/gettingstarted/urls.py +++ /dev/null @@ -1,21 +0,0 @@ -from django.urls import path, include - -from django.contrib import admin - -admin.autodiscover() - -import hello.views - -# To add a new path, first import the app: -# import blog -# -# Then add the new path: -# path('blog/', blog.urls, name="blog") -# -# Learn more here: https://docs.djangoproject.com/en/2.1/topics/http/urls/ - -urlpatterns = [ - path("", hello.views.index, name="index"), - path("db/", hello.views.db, name="db"), - path("admin/", admin.site.urls), -] diff --git a/gettingstarted/wsgi.py b/gettingstarted/wsgi.py deleted file mode 100644 index 3c528d7ce..000000000 --- a/gettingstarted/wsgi.py +++ /dev/null @@ -1,16 +0,0 @@ -""" -WSGI config for gettingstarted project. - -It exposes the WSGI callable as a module-level variable named ``application``. - -For more information on this file, see -https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/ -""" - -import os - -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings") - -from django.core.wsgi import get_wsgi_application - -application = get_wsgi_application() diff --git a/hello/__init__.py b/hello/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/hello/admin.py b/hello/admin.py deleted file mode 100644 index 8c38f3f3d..000000000 --- a/hello/admin.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.contrib import admin - -# Register your models here. diff --git a/hello/migrations/0001_initial.py b/hello/migrations/0001_initial.py deleted file mode 100644 index 99c4a82a5..000000000 --- a/hello/migrations/0001_initial.py +++ /dev/null @@ -1,23 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.1 on 2016-01-27 21:54 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='Greeting', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('when', models.DateTimeField(auto_now_add=True, verbose_name=b'date created')), - ], - ), - ] diff --git a/hello/migrations/__init__.py b/hello/migrations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/hello/models.py b/hello/models.py deleted file mode 100644 index 8229092ef..000000000 --- a/hello/models.py +++ /dev/null @@ -1,5 +0,0 @@ -from django.db import models - -# Create your models here. -class Greeting(models.Model): - when = models.DateTimeField("date created", auto_now_add=True) diff --git a/hello/static/lang-logo.png b/hello/static/lang-logo.png deleted file mode 100644 index f04aff1e38eeaeadba93390eb5cd356388b8a9f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2217 zcmaJ@c~}!?8V{ES5J5Ras&x#4Sjb5@5(!5xzz~)VpeP8&WPm)7Og4-ru!tat1eHTn zltSYHA_!`w93BV~D@C_zU8Rby1Vxl08WH5yPAJ%Y_HjEi-+bTu&ii}c-+TNq%8+1x zGZQ-#6bfY)7{KHqyHK~#^N_dn*`Y9GTMDxx;7}+Qmh)vG%1;Pw1%W^@KMv%9d|~oG zIzTTJ%D_n!76C_agQx;XjN|KUa0;;$L8DM!J_;#ckO0EKRxnN^p<&)$ZovQ|Aq}&^ zjZ5H48DP99AVmg-rUZuxQW69dA;!lW@KR6_2VxNB0}64XB#Ek^VP^bNk+V*X#{e@X zZ~_hU2dM~d2*7}3AmD~`#|j8UGT=eM5#8K9C>|~V36b#xPdtf$B~Yktu2cdEn7uGa zG?_4#%44!;V<8d^6A!~uDjqMF%W-m793+dw6Dbr5oq!3gUTS60}VwK>87DKLmkb!&{l7&G~ z;#~Ja;vpDHiie~CgE7-Bz=_Kjh$K4Y8eM^B`GPXhc2LNcL1JL0LR8TgSg;u+7K!EI z%JQQSXEGoW=nOW6@2aP|oS1Q;s&z#P{JJq*ux-`bs~p_~-7+ zYD!+5s{VEjH2F#WiNE5*bmM5(KqPXLZ^hPSoB02X&hmBAUulu+i_XGW=pRQ!#gfm* z*)PnO7uCx(dwTXw589+YDDm~GGV?M_`})m%A0wZI@=NXRjXkbfQIn1L0w{Cms)F9? z?C#8%-OkGg-=n9zuYBj5>zv#7@T(0y{kG1Uj)olj0yfz=dQ_hhdra?KGa>CYUyAPdqmBD`~BUt_i4qwX765iYW=nKiAU_9J9Q0(BfV3V zV^?FYb{F8ZquO*UtG$cOu@`FRbI6?+HmSQS4B1ht)@C>T@rTUjG*PItqQM=w_mW2W zv8OGfsm>9w6c<+bHClECx5w)bT{uzMj9ZVzvrqnDm^~C5;Lqb25#AheDhs$hl3Muq z=0v_o!KgmeY9Zc*zlL|HxhMYxB|Ns+c4&KQ{M&2yvnFk8^a3CUU+?tMHt1joO&(o4 zx~NKSy6n12d)d7!ZC-R#+tq3^s=v3N-C2CTR_OFymPeba%ltyG=}rS5t9$B~203TE zqAn`WXtrsC$MF7>huqf$hL`mK>#OghuCuPbj{T~CMcu6f=SH#upZ+Uar0U~qouzC2 zf9+x$6!28NFZv{Pw<5LVroXjzpVVX=yr-;tN-sD)&QUNm)>$08^wQv_|G15DBVBeF znQsW$cJ_hAo@I!NKBhm_u-NuQ=2`ixlURs{b*E^Ectmrrg--%)^>abZ(@5_(; z+*?O$8wWUv=Q+j;mZ~3aW)wPP$ye2&he;{J_4#EJznMP@>76JR_I6} zcAeZD`|8mvQTNaXEQfLQ2(iCln3EXXG#I5Y&1h=LD>QDLb}2XQu~oMYA483|uU8wF zD;>2q{WZrn-xyo~ zjZbW-mOahOG~`9BUYE0aNR+F*l>MnFDAnDy!KEyyWe;pXFZJ|wv?|*8qHArJiuo?G zXF$8RPqO-mRd{C5eQOS|{}sjZMf~`>?F9|49b2BXZ|a<`y5ZfN;1!k$svfLtLywy& zIoS&W&K};E%B4;|W?6#tn-*F2D`RR-b;Ol7|F+Sx!oaQ;^COo9cC(uMOrLd!TcBBhA$<`#BgBvnSY=qCk>`Ij*84tM aZ$a%}dZnx*#!~kSf(m2>Gtbhu?D`$|L6nF9 diff --git a/hello/templates/base.html b/hello/templates/base.html deleted file mode 100644 index 97ec07386..000000000 --- a/hello/templates/base.html +++ /dev/null @@ -1,83 +0,0 @@ - - - -Python Getting Started on Heroku - - - - - - - - -{% block content %}{% endblock %} - - - diff --git a/hello/templates/db.html b/hello/templates/db.html deleted file mode 100644 index e0e03d4c6..000000000 --- a/hello/templates/db.html +++ /dev/null @@ -1,21 +0,0 @@ -{% extends "base.html" %} -{% load staticfiles %} - -{% block content %} -
- - -

Page View Report

- - -
    - -{% for greeting in greetings %} -
  • {{ greeting.when }}
  • -{% endfor %} - -
- -
- -{% endblock %} \ No newline at end of file diff --git a/hello/templates/index.html b/hello/templates/index.html deleted file mode 100644 index 8af29028b..000000000 --- a/hello/templates/index.html +++ /dev/null @@ -1,58 +0,0 @@ -{% extends "base.html" %} -{% load staticfiles %} - -{% block content %} - -
-
- -

Getting Started with Python on Heroku

-

This is a sample Python application deployed to Heroku. It's a reasonably simple app - but a good foundation for understanding how to get the most out of the Heroku platform.

- Getting Started with Python - Source on GitHub -
-
-
- -
-
-
-

How this sample app works

-
    -
  • This app was deployed to Heroku, either using Git or by using Heroku Button on the repository.
  • - -
  • When Heroku received the source code, it fetched all the dependencies in the Pipfile, creating a deployable slug.
  • -
  • The platform then spins up a dyno, a lightweight container that provides an isolated environment in which the slug can be mounted and executed.
  • -
  • You can scale your app, manage it, and deploy over 150 add-on services, from the Dashboard or CLI.
  • -
-
-
-

Next Steps

-
    -
  • If you are following the Getting Started guide, then please head back to the tutorial and follow the next steps!
  • -
  • If you deployed this app by deploying the Heroku Button, then in a command line shell, run:
  • -
      -
    • git clone https://github.com/heroku/python-getting-started.git - this will create a local copy of the source code for the app
    • -
    • cd python-getting-started - change directory into the local source code repository
    • -
    • heroku git:remote -a <your-app-name> - associate the Heroku app with the repository
    • -
    • You'll now be set up to run the app locally, or deploy changes to Heroku
    • -
    -
-

Helpful Links

- -
-
- -
-{% endblock %} diff --git a/hello/tests.py b/hello/tests.py deleted file mode 100644 index 9b06366a5..000000000 --- a/hello/tests.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.contrib.auth.models import AnonymousUser, User -from django.test import TestCase, RequestFactory - -from .views import index - - -class SimpleTest(TestCase): - def setUp(self): - # Every test needs access to the request factory. - self.factory = RequestFactory() - - def test_details(self): - # Create an instance of a GET request. - request = self.factory.get("/") - request.user = AnonymousUser() - - # Test my_view() as if it were deployed at /customer/details - response = index(request) - self.assertEqual(response.status_code, 200) diff --git a/hello/views.py b/hello/views.py deleted file mode 100644 index c2480724b..000000000 --- a/hello/views.py +++ /dev/null @@ -1,19 +0,0 @@ -from django.shortcuts import render -from django.http import HttpResponse - -from .models import Greeting - -# Create your views here. -def index(request): - # return HttpResponse('Hello from Python!') - return render(request, "index.html") - - -def db(request): - - greeting = Greeting() - greeting.save() - - greetings = Greeting.objects.all() - - return render(request, "db.html", {"greetings": greetings}) diff --git a/manage.py b/manage.py index eb3ab8af5..826923ac5 100755 --- a/manage.py +++ b/manage.py @@ -1,10 +1,14 @@ -#!/usr/bin/env python -import os +from sshtunnel import SSHTunnelForwarder import sys -if __name__ == "__main__": - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gettingstarted.settings") +args = sys.argv - from django.core.management import execute_from_command_line +server = SSHTunnelForwarder( + ('example.com', 22), + ssh_username="name", + ssh_password="pass", + remote_bind_address=('0.0.0.0', 8080), + local_bind_address=('0.0.0.0', int(args[1])) +) - execute_from_command_line(sys.argv) +server.start() diff --git a/requirements.txt b/requirements.txt index 4af6a3765..79a240c44 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1 @@ -django -gunicorn -django-heroku \ No newline at end of file +sshtunnel