From 51e944b45541caaf55f35b7f2360b14365109187 Mon Sep 17 00:00:00 2001 From: Kai Hendry Date: Tue, 30 Aug 2016 21:53:41 +0800 Subject: [PATCH] Dockerize --- Dockerfile | 6 ++---- Makefile | 7 ++----- README.md | 52 +++++++++++---------------------------------------- www/oauth.php | 9 +++------ 4 files changed, 18 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index be6a111..15d4e06 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM alpine:latest -MAINTAINER Kai Hendry +MAINTAINER Kai Hendry RUN apk upgrade --update --available && \ apk add \ @@ -21,9 +21,7 @@ ADD php-fpm.ini /etc/supervisor.d/php-fpm.ini ADD nginx.ini /etc/supervisor.d/nginx.ini RUN mkdir -p /srv/http/u -VOLUME /srv/http/u/ -VOLUME /srv/http/ -VOLUME /var/log/nginx +RUN chmod -R 777 /srv/http/u EXPOSE 80 diff --git a/Makefile b/Makefile index 07485f3..3859cea 100644 --- a/Makefile +++ b/Makefile @@ -10,11 +10,8 @@ build: docker build -t $(REPO) . start: - docker run -d --name $(NAME) -v /mnt/2tb/greptweet/:/srv/http/u -v $(PWD)/www:/srv/http/ -v $(PWD)/logs:/var/log/nginx/ -p 81:80 $(REPO) - -stop: - docker stop $(NAME) - docker rm $(NAME) + #docker run --rm -it --name $(NAME) -v /mnt/raid1/greptweet:/srv/http/u -v $(PWD)/www:/srv/http/ -v $(PWD)/logs:/var/log/nginx/ -p 81:80 $(REPO) + docker run --rm -it --name $(NAME) --env-file envfile -v /tmp/g:/srv/http/u -p 81:80 $(REPO) sh: docker exec -it $(NAME) /bin/sh diff --git a/README.md b/README.md index 1a17191..9cdc7bf 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,20 @@ -# +# Greptweet -Offline Greptweet on Chrome IOS +## Setup -* Image VIRTUAL SIZE <100MB (Docker) -* Uses [HTML offline feature](http://www.whatwg.org/specs/web-apps/current-work/multipage/offline.html) -* Aims to [suck less](http://suckless.org) by keeping lines of code low -* Can run from command line -* **Please** review and comment on the code! +Set `access_token` in envfile. You should be able to get it from [creating a new Twitter app](https://dev.twitter.com/apps/new). -# Known limitations + curl -X POST "https://api.twitter.com/oauth2/token" -d "grant_type=client_credentials" -u consumerKey:consumerSecret -* API only allows 3200 tweets to be downloaded this way at one time :( -* 300 API limit using a [Application only Auth](https://dev.twitter.com/docs/auth/application-only-auth) bearer token (which doesn't seem to expire...) -* Won't work on protected accounts (duh!) -* No @mentions or DMs from other accounts + echo 'access_token=secret' > envfile + docker run -d --name greptweet --env-file envfile -p 8888:80 hendry/greptweet -# API +# Maintenance -Invoke a fetch of a TWITTER_USERNAME by accessing the URL: +Running it again: - http://greptweet.com/f/TWITTER_USERNAME + docker start greptweet -Last 4 tweets: +Backing it up: - curl --compressed -s http://greptweet.com/u/webconverger/tweets.txt | head - -# Getting a Bearer Token - -When you clone and attempt to run this opensource project you will notice that -you are missing a `secret.php` file, this file contains one setting -`$bearer_token`. To [create a bearer -token](https://dev.twitter.com/docs/auth/application-only-auth): - -1. [Create a new Twitter app](https://dev.twitter.com/apps/new) -1. Under OAuth settings, make a note of the **Consumer key** and **Consumer secret** -1. Now retrieve the bearer token by building a request with curl: - - - curl -X POST --verbose "https://api.twitter.com/oauth2/token" -d "grant_type=client_credentials" -u consumerKey:consumerSecret - -The response should end like: - - {"access_token":"SECRETEXAMPLESTRING","token_type":"bearer"} - -Save that SECRETEXAMPLESTRING to www/secret.php: - - + docker cp greptweet:/srv/http/u/ /tmp/backup diff --git a/www/oauth.php b/www/oauth.php index ee3d9bd..b4504d0 100755 --- a/www/oauth.php +++ b/www/oauth.php @@ -4,12 +4,12 @@ if (empty($argv[1])) { exit(1); } $urlargs = $argv[1]; -function fetch($bearer_token, $query){ +function fetch($query){ $url = "https://api.twitter.com/1.1/statuses/user_timeline.json?"; $headers = array( "GET /1.1/statuses/user_timeline.json?".$query." HTTP/1.1", "Host: api.twitter.com", - "Authorization: Bearer ".$bearer_token."", + "Authorization: Bearer ".getenv('access_token')."", ); $ch = curl_init(); // setup a curl curl_setopt($ch, CURLOPT_URL, $url.$query); // set url to send to @@ -29,8 +29,5 @@ function fetch($bearer_token, $query){ } -// $bearer_token = get_bearer_token(); // bearer token seems to last -require("secret.php"); // contains $bearer_token -print fetch($bearer_token, $urlargs); // search for the work 'test' -//invalidate_bearer_token($bearer_token); // invalidate the token +print fetch($urlargs); // search for the work 'test' ?>