Skip to content

Commit f1c9f7e

Browse files
Merge pull request #18 from stanfordnmbl/treadmill_gait_analysis
Add treadmill gait analysis
2 parents 9a5a424 + 1e821e9 commit f1c9f7e

16 files changed

+3523
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This workflow will build and push a new container image to Amazon ECR,
2+
# and then will deploy a new task definition to Amazon ECS, on every push
3+
# to the master branch.
4+
#
5+
# To use this workflow, you will need to complete the following set-up steps:
6+
#
7+
# 1. Create an ECR repository to store your images.
8+
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
9+
# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name.
10+
# Replace the value of `aws-region` in the workflow below with your repository's region.
11+
#
12+
# 2. Create an ECS task definition, an ECS cluster, and an ECS service.
13+
# For example, follow the Getting Started guide on the ECS console:
14+
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun
15+
# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names.
16+
#
17+
# 3. Store your ECS task definition as a JSON file in your repository.
18+
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`.
19+
# Replace the value of `task-definition` in the workflow below with your JSON file's name.
20+
# Replace the value of `container-name` in the workflow below with the name of the container
21+
# in the `containerDefinitions` section of the task definition.
22+
#
23+
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
24+
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
25+
# and best practices on handling the access key credentials.
26+
27+
on:
28+
push:
29+
branches:
30+
- dev
31+
paths:
32+
- 'treadmill_gait_analysis/**'
33+
workflow_dispatch:
34+
35+
name: DEV Analysis "treadmill gait analysis" build & deployment
36+
37+
jobs:
38+
deploy:
39+
name: Deploy
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v1
45+
46+
- name: Configure AWS credentials
47+
uses: aws-actions/configure-aws-credentials@v1
48+
with:
49+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
50+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
51+
aws-region: us-west-2
52+
53+
- name: Login to Amazon ECR
54+
id: login-ecr
55+
uses: aws-actions/amazon-ecr-login@v1
56+
57+
- name: Build, tag, and push image to Amazon ECR
58+
id: build-image
59+
env:
60+
IMAGE_TAG: latest # ${{ github.sha }}
61+
run: |
62+
# Build a docker container and
63+
# push it to ECR so that it can
64+
# be deployed to ECS.
65+
cd treadmill_gait_analysis
66+
docker build -f Dockerfile -t 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis-dev:$IMAGE_TAG .
67+
docker push 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis-dev:$IMAGE_TAG
68+
echo "::set-output name=image::660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis-dev:$IMAGE_TAG"
69+
70+
- name: Force deployment
71+
env:
72+
IMAGE_TAG: latest # ${{ github.sha }}
73+
run: |
74+
aws lambda update-function-code --function-name treadmill-gait-analysis-dev --image-uri 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis-dev:$IMAGE_TAG | jq 'if .Environment.Variables.API_TOKEN? then .Environment.Variables.API_TOKEN = "REDACTED" else . end'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This workflow will build and push a new container image to Amazon ECR,
2+
# and then will deploy a new task definition to Amazon ECS, on every push
3+
# to the master branch.
4+
#
5+
# To use this workflow, you will need to complete the following set-up steps:
6+
#
7+
# 1. Create an ECR repository to store your images.
8+
# For example: `aws ecr create-repository --repository-name my-ecr-repo --region us-east-2`.
9+
# Replace the value of `ECR_REPOSITORY` in the workflow below with your repository's name.
10+
# Replace the value of `aws-region` in the workflow below with your repository's region.
11+
#
12+
# 2. Create an ECS task definition, an ECS cluster, and an ECS service.
13+
# For example, follow the Getting Started guide on the ECS console:
14+
# https://us-east-2.console.aws.amazon.com/ecs/home?region=us-east-2#/firstRun
15+
# Replace the values for `service` and `cluster` in the workflow below with your service and cluster names.
16+
#
17+
# 3. Store your ECS task definition as a JSON file in your repository.
18+
# The format should follow the output of `aws ecs register-task-definition --generate-cli-skeleton`.
19+
# Replace the value of `task-definition` in the workflow below with your JSON file's name.
20+
# Replace the value of `container-name` in the workflow below with the name of the container
21+
# in the `containerDefinitions` section of the task definition.
22+
#
23+
# 4. Store an IAM user access key in GitHub Actions secrets named `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`.
24+
# See the documentation for each action used below for the recommended IAM policies for this IAM user,
25+
# and best practices on handling the access key credentials.
26+
27+
on:
28+
push:
29+
branches:
30+
- main
31+
paths:
32+
- 'treadmill_gait_analysis/**'
33+
workflow_dispatch:
34+
35+
name: PROD Analysis "treadmill gait analysis" build & deployment
36+
37+
jobs:
38+
deploy:
39+
name: Deploy
40+
runs-on: ubuntu-latest
41+
42+
steps:
43+
- name: Checkout
44+
uses: actions/checkout@v1
45+
46+
- name: Configure AWS credentials
47+
uses: aws-actions/configure-aws-credentials@v1
48+
with:
49+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
50+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
51+
aws-region: us-west-2
52+
53+
- name: Login to Amazon ECR
54+
id: login-ecr
55+
uses: aws-actions/amazon-ecr-login@v1
56+
57+
- name: Build, tag, and push image to Amazon ECR
58+
id: build-image
59+
env:
60+
IMAGE_TAG: latest # ${{ github.sha }}
61+
run: |
62+
# Build a docker container and
63+
# push it to ECR so that it can
64+
# be deployed to ECS.
65+
cd treadmill_gait_analysis
66+
docker build -f Dockerfile -t 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis:$IMAGE_TAG .
67+
docker push 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis:$IMAGE_TAG
68+
echo "::set-output name=image::660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis:$IMAGE_TAG"
69+
70+
- name: Force deployment
71+
env:
72+
IMAGE_TAG: latest # ${{ github.sha }}
73+
run: |
74+
aws lambda update-function-code --function-name treadmill-gait-analysis --image-uri 660440363484.dkr.ecr.us-west-2.amazonaws.com/opencap-analysis/treadmill_gait_analysis:$IMAGE_TAG | jq 'if .Environment.Variables.API_TOKEN? then .Environment.Variables.API_TOKEN = "REDACTED" else . end'

treadmill_gait_analysis/.dockerignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.git
2+
Data/
3+
.env
4+
docker

treadmill_gait_analysis/.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__pycache__
2+
.env
3+
*.log
4+
*.ipynb_checkpoints
5+
Data/*
6+
7+
*DS_Store

treadmill_gait_analysis/Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM stanfordnmbl/opensim-python:4.3
2+
3+
ARG FUNCTION_DIR="/function"
4+
5+
RUN apt-get update && \
6+
apt-get install -y \
7+
build-essential \
8+
python3-dev \
9+
g++ \
10+
make \
11+
cmake \
12+
unzip \
13+
libcurl4-openssl-dev
14+
15+
# Copy function code
16+
RUN mkdir -p ${FUNCTION_DIR}
17+
COPY ./requirements.txt /requirements.txt
18+
# Install the requirements.txt
19+
RUN python3.8 -m pip install --no-cache-dir -r /requirements.txt
20+
RUN python3.8 -m pip install --target ${FUNCTION_DIR} awslambdaric
21+
22+
ADD https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie /usr/bin/aws-lambda-rie
23+
RUN chmod +x /usr/bin/aws-lambda-rie
24+
25+
COPY ./function ${FUNCTION_DIR}
26+
RUN chmod +x ${FUNCTION_DIR}/entrypoint
27+
WORKDIR ${FUNCTION_DIR}
28+
29+
ENTRYPOINT ["./entrypoint"]
30+
CMD ["handler.handler"]
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.8'
2+
3+
services:
4+
gait_analysis:
5+
# platform: linux/amd64
6+
build:
7+
context: .
8+
dockerfile: ./Dockerfile
9+
ports:
10+
- 9005:8080
11+
env_file:
12+
- ./.env
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
if [ -z "${AWS_LAMBDA_RUNTIME_API}" ]; then
3+
exec /usr/bin/aws-lambda-rie /usr/bin/python3.8 -m awslambdaric $@
4+
else
5+
exec /usr/bin/python3.8 -m awslambdaric $@
6+
fi

0 commit comments

Comments
 (0)