Skip to content

Commit 72c2095

Browse files
committed
serverless support, change default port
1 parent 444673e commit 72c2095

File tree

4 files changed

+26
-10
lines changed

4 files changed

+26
-10
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# FROM python:3.6
22
FROM public.ecr.aws/bitnami/python:3.6
3+
COPY --from=public.ecr.aws/m7b0o7h1/secret-env-vars-wrapper:latest-x86 /opt /opt
4+
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.3.2-x86_64 /lambda-adapter /opt/extensions/lambda-adapter
35

46
# Create app directory
57
WORKDIR /app
@@ -16,6 +18,6 @@ RUN python3 -m venv venv
1618
# Copy the whole folder inside the Image filesystem
1719
COPY . .
1820

19-
EXPOSE 80
21+
EXPOSE 8000
2022

21-
CMD gunicorn --bind 0.0.0.0:80 wsgi:app
23+
CMD /opt/tinystacks-secret-env-vars-wrapper gunicorn --bind 0.0.0.0:8000 wsgi:app

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ PG_PORT=<postgres_port>
151151

152152
to get all the items:
153153
```
154-
curl --location --request GET '127.0.0.1:80/postgres-item'
154+
curl --location --request GET '127.0.0.1:8000/postgres-item'
155155
```
156156

157157
an example to create a new item:
158158
```
159-
curl --location --request POST 'localhost:80/postgres-item' --header 'Content-Type: application/json' --data-raw '{"title":"theTitle","content":"theContent"}'
159+
curl --location --request POST 'localhost:8000/postgres-item' --header 'Content-Type: application/json' --data-raw '{"title":"theTitle","content":"theContent"}'
160160
```
161161

162162
### Dockerfile
@@ -175,10 +175,10 @@ If you have Docker installed, you can build and try out the sample application l
175175
docker build -t tinystacks/flask-crud-app:latest .
176176
```
177177

178-
Once built, run the Docker command locally, mapping port 8080 on your host machine to port 80 on the container:
178+
Once built, run the Docker command locally, mapping port 8080 on your host machine to port 8000 on the container:
179179

180180
```
181-
docker run -p 8080:80 -d tinystacks/flask-crud-app:latest
181+
docker run -p 8080:8000 -d tinystacks/flask-crud-app:latest
182182
```
183183

184184
To test that the server is running, test its `/ping` endpoint from the command line. This time, you will change the port to 8080 to test that it's running from the running Docker container:
@@ -246,10 +246,10 @@ If you already have an existing Flask application, you can use the core files in
246246

247247
If your project is already Dockerized (i.e., it has its own Dockerfile), then simply copy over the `build.yml` and `release.yml` files into the root of your existing project.
248248

249-
If your project is not Dockerized, you will also need to copy over the Dockerfile included in this sample. If your application uses a different port than port 80, you will also need to update the `EXPOSE` line in the Dockerfile to use a different port:
249+
If your project is not Dockerized, you will also need to copy over the Dockerfile included in this sample. If your application uses a different port than port 8000, you will also need to update the `EXPOSE` line in the Dockerfile to use a different port:
250250

251251
```Dockerfile
252-
EXPOSE 80
252+
EXPOSE 8000
253253
```
254254

255255
## Known Limitations

release.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,18 @@ phases:
1010
on-failure: CONTINUE
1111
commands:
1212
- region="${STAGE_REGION:-$AWS_REGION}"
13-
- if [ -z "$SERVICE_NAME" ] || [ "$SERVICE_NAME" == "placeholder" ]; then echo 'Service is not ready yet. Repository tagged correctly, exiting now'; else aws ecs update-service --service $SERVICE_NAME --cluster $CLUSTER_ARN --region $region --force-new-deployment; fi
13+
- |
14+
if [ ! -z "$LAMBDA_FUNCTION_NAME" -a "$LAMBDA_FUNCTION_NAME" != "placeholder" ];
15+
then
16+
aws lambda update-function-code --function-name "$LAMBDA_FUNCTION_NAME" --image-uri "$ECR_IMAGE_URL:$STAGE_NAME" --region $region
17+
imageSha=$(docker images --no-trunc --quiet $ECR_IMAGE_URL:$PREVIOUS_STAGE_NAME);
18+
aws lambda tag-resource --resource "$LAMBDA_FUNCTION_ARN" --tags "IMAGE_SHA=$imageSha"
19+
else
20+
echo 'Not a serverless stage'
21+
if [ -z "$SERVICE_NAME" ] || [ "$SERVICE_NAME" == "placeholder" ];
22+
then
23+
echo 'Service is not ready yet. Repository tagged correctly, exiting now';
24+
else
25+
aws ecs update-service --service $SERVICE_NAME --cluster $CLUSTER_ARN --region $region --force-new-deployment;
26+
fi
27+
fi

wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
if __name__ == '__main__':
55
stage = os.environ.get('STAGE', 'local')
6-
the_port = 8000 if stage=='local' else 80
6+
the_port = 8000
77
app.run(host='0.0.0.0', port=the_port)

0 commit comments

Comments
 (0)