Skip to content

Commit 23ce57b

Browse files
Merge branch 'main' of github.com:code-dot-org/aiproxy into redirect-http-to-https
2 parents d2e84a3 + 316f5ad commit 23ce57b

File tree

6 files changed

+45
-32
lines changed

6 files changed

+45
-32
lines changed

Dockerfile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
FROM python:3.11-slim
22

3-
RUN pip install Flask
4-
53
WORKDIR /app
64
COPY requirements.txt .
75

8-
RUN pip install -r requirements.txt
6+
RUN pip install --no-cache-dir -r requirements.txt
97

108
COPY ./test /app/test
119
COPY ./lib /app/lib

ci-build.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
if [ -n "$CODEBUILD_BUILD_ID" ]; then
6+
# CodeBuild environment
7+
IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
8+
else
9+
# Local Git repository
10+
IMAGE_TAG=$(git rev-parse --short HEAD)
11+
fi
12+
13+
IMAGE_NAME=aiproxy
14+
15+
echo "Building Docker Image ${IMAGE_NAME}:${IMAGE_TAG}..."
16+
docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .

ci-lint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
echo "Validating Cloudformation Templates..."
6+
cfn-lint cicd/1-setup/*.template.yml
7+
cfn-lint cicd/2-cicd/*.template.yml
8+
cfn-lint cicd/3-app/aiproxy/template.yml
9+
10+
echo "Validating Dockerfile..."
11+
docker run --rm -i hadolint/hadolint < Dockerfile

cicd/3-app/aiproxy/buildspec.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ phases:
1616
commands:
1717
- echo Logging in to Docker Hub...
1818
- echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USERNAME --password-stdin
19+
20+
- echo "Logging in to AWS ECR..."
21+
- ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
22+
- AWS_REGION=us-east-1
23+
- ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
24+
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
1925

2026
build:
2127
# This will build and push the docker image to ECR and package the
@@ -29,25 +35,17 @@ phases:
2935

3036
- cd $CODEBUILD_SRC_DIR
3137

32-
- echo "Validating Cloudformation Templates..."
33-
- cfn-lint cicd/1-setup/*.template.yml
34-
- cfn-lint cicd/2-cicd/*.template.yml
35-
- cfn-lint cicd/3-app/aiproxy/template.yml
38+
- ./ci-lint.sh
39+
40+
- echo "Running Unit Tests..."
41+
- echo "This is where I would run my unit tests"
3642

3743
- echo "Building Docker Image..."
3844
- IMAGE_NAME=aiproxy
3945
- IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7} # short commit hash
4046
- docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
4147

42-
- echo "Running Unit Tests..."
43-
- echo "This is where I would run my unit tests"
44-
4548
- echo "Pushing Docker Image to ECR..."
46-
- ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
47-
- AWS_REGION=us-east-1
48-
- ECR_REGISTRY="${ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com"
49-
- aws ecr get-login-password --region ${AWS_REGION} | docker login --username AWS --password-stdin ${ECR_REGISTRY}
50-
5149
- docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${ECR_REPOSITORY}:${IMAGE_TAG}
5250
- docker tag ${IMAGE_NAME}:${IMAGE_TAG} ${ECR_REPOSITORY}:latest
5351
- docker push ${ECR_REPOSITORY}:${IMAGE_TAG}

cicd/3-app/aiproxy/pr-buildspec.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,15 @@ phases:
1717
- echo Logging in to Docker Hub...
1818
- echo $DOCKER_HUB_PAT | docker login -u $DOCKER_HUB_USERNAME --password-stdin
1919

20-
2120
build:
22-
# This should be moved to a shell script if it gets more complicated.
2321
commands:
2422
- set -e
2523

2624
- BRANCH_NAME=${CODEBUILD_WEBHOOK_HEAD_REF#"refs/heads/"}
2725
- ARTIFACT_PATH=branch/$BRANCH_NAME/$CODEBUILD_BUILD_NUMBER
26+
- COMMIT_HASH=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
2827

2928
- cd $CODEBUILD_SRC_DIR
3029

31-
- echo "Validating Cloudformation Templates..."
32-
- cfn-lint cicd/1-setup/*.template.yml
33-
- cfn-lint cicd/2-cicd/*.template.yml
34-
- cfn-lint cicd/3-app/aiproxy/template.yml
35-
36-
- echo "Building Docker Image..."
37-
- IMAGE_NAME=aiproxy
38-
- IMAGE_TAG=${CODEBUILD_RESOLVED_SOURCE_VERSION:0:7}
39-
- docker build -t ${IMAGE_NAME}:${IMAGE_TAG} .
40-
41-
- echo "Running Unit Tests..."
42-
- docker run --rm ${IMAGE_NAME}:${IMAGE_TAG} python -m unittest test_app.py
43-
44-
- echo "Pushing Docker Image to ECR..."
45-
- echo "This is where I would push the docker image to ECR, when I get around to it"
30+
- ./ci-lint.sh
31+
- ./ci-build.sh

src/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
import openai
1717

1818
def create_app(test_config=None):
19+
20+
# divide by zero LOL
21+
print(1/0)
22+
1923
# create and configure the app
2024
app = Flask(__name__, instance_relative_config=True)
2125
app.config.from_mapping(

0 commit comments

Comments
 (0)