Skip to content

Commit

Permalink
Dockerfile Updates (#4119)
Browse files Browse the repository at this point in the history
  • Loading branch information
dealako authored Aug 31, 2023
1 parent f02c3f7 commit fafed8c
Showing 6 changed files with 55 additions and 73 deletions.
60 changes: 11 additions & 49 deletions .github/workflows/build-docker-pr.yml
Original file line number Diff line number Diff line change
@@ -9,9 +9,6 @@ on:
- main

env:
AWS_REGION: us-east-1
AWS_ECR_REGION: us-east-1
AWS_PROFILE: lf-cla
STAGE: dev
REPOSITORY: lfx-easycla-dev
ECR_HOST: ${{secrets.AWS_ACCOUNT_ID}}.dkr.ecr.us-east-1.amazonaws.com
@@ -22,61 +19,26 @@ jobs:
environment: dev
steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v2
#- name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v2
- name: Available Build Platforms
run: echo ${{ steps.buildx.outputs.platforms }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_KEY }}
aws-region: us-east-1
role-duration-seconds: 900
- name: Setup AWS Profile
run: |
echo "Installing Profile '${AWS_PROFILE}'..."
mkdir -p ~/.aws
touch ~/.aws/config
if ! grep -q AWS_PROFILE ~/.aws/config; then
printf "[profile ${AWS_PROFILE}]\nregion=${AWS_REGION}\noutput=json" > ~/.aws/config
echo "Added ${AWS_PROFILE} profile to ~/.aws/config"
else
echo "Skipped adding ${AWS_PROFILE} to ~/.aws/config - already there"
fi
touch ~/.aws/credentials
if ! grep -q AWS_PROFILE ~/.aws/credentials; then
printf "[${AWS_PROFILE}]\naws_access_key_id=${{ secrets.AWS_ACCESS_KEY }}\naws_secret_access_key=${{ secrets.AWS_SECRET_KEY }}" > ~/.aws/credentials
echo "Added ${AWS_PROFILE} profile to ~/.aws/credentials"
else
echo "Skipped adding ${AWS_PROFILE} to ~/.aws/credentials - already there"
fi
if ! grep -q AWS_PROFILE ${HOME}/.bashrc; then
echo "export AWS_PROFILE=${AWS_PROFILE}" >> ${HOME}/.bashrc
echo "Added ${AWS_PROFILE} profile to ${HOME}/.bashrc"
else
echo "Skipped adding ${AWS_PROFILE} to ${HOME}/.bashrc - already there"
fi
- name: Build Docker Image
working-directory: cla-backend
run: |
# Create a new builder, named container, that uses the Docker container driver
echo "Creating a new builder container..."
docker buildx create --name container --driver=docker-container
#echo "Creating a new builder container..."
#docker buildx create --name container --driver docker-container
echo "Building image with tag: ${ECR_HOST}/${REPOSITORY}:${{github.sha}}"
docker buildx build --platform=linux/arm64 --builder=container --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker build --platform linux/amd64 --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
echo "Building image with tag: ${ECR_HOST}/${REPOSITORY}:latest"
docker buildx build --platform=linux/arm64 --builder=container --tag ${ECR_HOST}/${REPOSITORY}:latest .
docker build --platform linux/amd64 --tag ${ECR_HOST}/${REPOSITORY}:latest .
# Note, unlike when using the default docker driver, images built with the docker-container driver must be explicitly loaded into the local image store. Use the --load flag
echo "Loading the image into the image store..."
docker buildx build --platform=linux/arm64 --builder=container --load --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker buildx build --platform=linux/arm64 --builder=container --load --tag ${ECR_HOST}/${REPOSITORY}:latest .
docker build --platform linux/amd64 --load --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker build --platform linux/amd64 --load --tag ${ECR_HOST}/${REPOSITORY}:latest .
26 changes: 13 additions & 13 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -28,13 +28,13 @@ jobs:
go-version: '1.20.1'
- name: Go Version
run: go version
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v2
- name: Available Build Platforms
run: echo ${{ steps.buildx.outputs.platforms }}
#- name: Set up QEMU
# uses: docker/setup-qemu-action@v2
#- name: Set up Docker Buildx
# id: buildx
# uses: docker/setup-buildx-action@v2
#- name: Available Build Platforms
# run: echo ${{ steps.buildx.outputs.platforms }}
- name: Setup Node
uses: actions/setup-node@v3
with:
@@ -122,18 +122,18 @@ jobs:
working-directory: cla-backend
run: |
# Create a new builder, named container, that uses the Docker container driver
echo "Creating a new builder container..."
docker buildx create --name container --driver=docker-container
#echo "Creating a new builder container..."
#docker buildx create --name container --driver docker-container
echo "Building image with tag: ${ECR_HOST}/${REPOSITORY}:${{github.sha}}"
docker buildx build --platform=linux/amd64 --builder=container --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker build --platform=linux/amd64 --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
echo "Building image with tag: ${ECR_HOST}/${REPOSITORY}:latest"
docker buildx build --platform=linux/amd64 --builder=container --tag ${ECR_HOST}/${REPOSITORY}:latest .
docker build --platform=linux/amd64 --tag ${ECR_HOST}/${REPOSITORY}:latest .
# Note, unlike when using the default docker driver, images built with the docker-container driver must be explicitly loaded into the local image store. Use the --load flag
echo "Loading the image into the image store..."
docker buildx build --platform=linux/amd64 --builder=container --load --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker buildx build --platform=linux/amd64 --builder=container --load --tag ${ECR_HOST}/${REPOSITORY}:latest .
docker build --platform=linux/amd64 --load --tag ${ECR_HOST}/${REPOSITORY}:${{github.sha}} .
docker build --platform=linux/amd64 --load --tag ${ECR_HOST}/${REPOSITORY}:latest .
- name: Publish Docker Image
run: |
aws ecr get-login-password --region ${AWS_ECR_REGION} | docker login --username AWS --password-stdin ${ECR_HOST}
13 changes: 9 additions & 4 deletions cla-backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -4,14 +4,19 @@
FROM public.ecr.aws/lambda/python:3.7

# Copy requirements.txt
COPY requirements.txt requirements-test.txt ${LAMBDA_TASK_ROOT}

COPY requirements.txt ${LAMBDA_TASK_ROOT}
# Copy function code
COPY *.py .serverless-wsgi serverless-authorizer.yml ${LAMBDA_TASK_ROOT}
COPY *.py ${LAMBDA_TASK_ROOT}
#COPY .serverless-wsgi ${LAMBDA_TASK_ROOT}
RUN echo '{"app":"cla.routes.__hug_wsgi__"}' > .serverless-wsgi
COPY serverless-authorizer.yml ${LAMBDA_TASK_ROOT}
# Add the CLA library folder
ADD /cla ${LAMBDA_TASK_ROOT}/cla
COPY /cla/ ${LAMBDA_TASK_ROOT}/cla/
COPY /helpers/ ${LAMBDA_TASK_ROOT}/helpers/
COPY /auth/ ${LAMBDA_TASK_ROOT}/auth/

# Install the specified packages
# RUN pip install --upgrade pip && pip install -r requirements.txt
RUN pip install -r requirements.txt

# Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile)
7 changes: 6 additions & 1 deletion cla-backend/Makefile
Original file line number Diff line number Diff line change
@@ -118,8 +118,13 @@ deploy-dynamodb-backups:
cd serverless-dynamodb-backups; \
../node_modules/.bin/serverless deploy --region us-east-1; \

#$(DOCKER_CMD) build --platform linux/arm64 -t easycla-python:latest .
build-docker-mac-dockertool:
docker build --platform linux/arm64 --tag 726224182707.dkr.ecr.us-east-1.amazonaws.com/lfx-easycla-dev:latest .
build-docker-mac-podmantool:
podman build --platform linux/arm64 --tag 726224182707.dkr.ecr.us-east-1.amazonaws.com/lfx-easycla-dev:latest .
build-docker-mac:
$(DOCKER_CMD) build --platform linux/arm64 -t easycla-python:latest .
$(DOCKER_CMD) build --platform linux/arm64 --tag 726224182707.dkr.ecr.us-east-1.amazonaws.com/lfx-easycla-dev:latest .
build-docker-linux: build-docker
build-docker:
$(DOCKER_CMD) build --platform linux/amd64 -t easycla-python:latest .
13 changes: 13 additions & 0 deletions cla-backend/run-docker-shell.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

# Copyright The Linux Foundation and each contributor to CommunityBridge.
# SPDX-License-Identifier=MIT

docker run \
--rm \
-it \
--name easycla-python-bash \
--entrypoint /bin/bash \
726224182707.dkr.ecr.us-east-1.amazonaws.com/lfx-easycla-dev:latest


9 changes: 3 additions & 6 deletions cla-backend/run-docker.sh
Original file line number Diff line number Diff line change
@@ -6,10 +6,10 @@
# In a separate terminal, you can then locally invoke the function using cURL:
# curl -XPOST "http://localhost:8080/2015-03-31/functions/function/invocations" -d '{"payload":"hello world!"}'

podman run \
docker run \
--rm \
--name easycla-python \
-it \
--name easycla-python \
-p 8080:8080 \
-e STAGE="${STAGE}" \
-e AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID}" \
@@ -59,7 +59,4 @@ podman run \
-e PLATFORM_AUTH0_AUDIENCE="${PLATFORM_AUTH0_AUDIENCE}" \
-e PLATFORM_GATEWAY_URL="${PLATFORM_GATEWAY_URL}" \
-e PLATFORM_MAINTAINERS="${PLATFORM_MAINTAINERS}" \
easycla-python:latest
# --entrypoint /bin/bash \


726224182707.dkr.ecr.us-east-1.amazonaws.com/lfx-easycla-dev:latest

0 comments on commit fafed8c

Please sign in to comment.