Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docker #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
FROM python:3.7
FROM python:3.7-alpine
RUN mkdir -p /app
RUN apk add --no-cache build-base
COPY requirements.txt /app
RUN pip install --no-cache-dir -r /app/requirements.txt \
&& apk del build-base

COPY api.py /app

RUN mkdir -p /home/project/strava-oauth
WORKDIR /home/project/strava-oauth
COPY requirements.txt /home/project/strava-oauth
RUN pip install --no-cache-dir -r requirements.txt
COPY . /home/project/strava-oauth
EXPOSE 5042

WORKDIR /app
CMD python api.py
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This repo comes with pre-configured *Dockerfile* and *docker-compose.yml*, which
make build
```

## Must
## Requirements

Before using set environmental variables that represent your [application](https://www.strava.com/settings/api):

Expand Down Expand Up @@ -38,34 +38,48 @@ In the web browser go to: *http://127.0.0.1:5042/authorize*
2. After authorization is granted, the browser will display a raw JSON with the authorization tokens
3. Take it from here and build on it

```
```json
Example Response
{
"token_type": "Bearer",
"access_token": "987654321234567898765432123456789",
"athlete": {
#{summary athlete representation}
// {summary athlete representation}
},
"refresh_token": "1234567898765432112345678987654321",
"expires_at": 1531378346,
"state": "https://github.com/sladkovm/strava-oauth"
}
```

## Run as a dockerized application
## Running in docker

First you need to build docker image from source code. This might take a while so be patient.

```bash
docker build -t strava-oauth .
```

After image is succesfully built, you can run it in docker container. Make sure you provide STRAVA_CLIENT_ID and STRAVA_CLIENT_SECRET to docker container.

Before you start, set the application url, where the Strava callbacks will be redirected:
```bash
docker container run --rm -p 5042:5042 -e STRAVA_CLIENT_ID=<the-actual-id> -e STRAVA_CLIENT_SECRET=<the-actual-secret> strava-oauth:latest
```

Before you start, the container also make sure you provide APP_URL if you are not working on http://localhost:5047

```bash
export APP_URL=<http://myapp.com>
docker container run --rm -p 5042:5042 -e STRAVA_CLIENT_ID=<the-actual-id> -e STRAVA_CLIENT_SECRET=<the-actual-secret> -e APP_URL="http://dev.myapp.com" strava-oauth:latest
```
In this case the callbacks will be redirected to `http://myapp.com:5042/authorization_successful`
In this case the callbacks will be redirected to `http://dev.myapp.com:5042/authorization_successful`

Some gotchas:
### Some gotchas

1. If you run docker directly from the terminal (e.g. not in the docker-machine), the docker containers will be spawned at the *localhost*. In this case you don't need to specify the *APP_URL*. The server will be run as in the *Quick start* case - at *http://127.0.0.1:5042/authorize*

2. If you run docker on the *docker-machine*, with a given IP, you will need to figure out how to redirect to this IP. The easiest way is to set `export APP_URL=dev.myapp.com`. Then add to the */etc/hosts* the following line: `<docker-machine IP> dev.myapp.com`. This will send all Strava redirects to the docker-machine IP
2. If you run docker on the *docker-machine*, with a given IP, you will need to figure out how to redirect to this IP. The easiest way is to set `export APP_URL=dev.myapp.com`. Then add to the */etc/hosts* the following line: `<docker-machine IP> dev.myapp.com`. This will send all Strava redirects to the docker-machine IP

3. Majority of browsers are caching redirect requests which means that your http://localhost:5042/authorize might get cached. If you changed your STRAVA_CLIENT_ID make sure that your browser is not returning you cached redirect.



Expand Down
3 changes: 2 additions & 1 deletion api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ def authorize_url():

@api.route("/")
def home(req, resp):
resp.text = "Welcome to strava-oauth"
app_url = os.getenv('APP_URL', 'http://localhost')
resp.text = f"Welcome to strava-oauth, to start authorization go to: {app_url}:5042/authorize"


@api.route("/client")
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
responder
loguru
request
responder==2.0.5
loguru==0.5.3
requests==2.24.0