Skip to content

Commit

Permalink
Replace two Makefiles with single one
Browse files Browse the repository at this point in the history
Instead of having single Makefile, each in separate Docker definition
folder, there is single Makefile to rule them all!

This includes as well renaming Docker folders for consistency and
clarity - i.e. fin-scrap-lambda is name of the image, no python-3.9.
  • Loading branch information
kniklas committed Jul 1, 2023
1 parent 819d6c6 commit ab547e5
Show file tree
Hide file tree
Showing 13 changed files with 85 additions and 85 deletions.
85 changes: 85 additions & 0 deletions examples/docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Makefile to build docker images for finscrap Python package
# Author: Kamil Niklasiński (c) 2023

BASE_IMAGE_NAME=fin-scrap-base
BASE_REPO_NAME=fin-scrap-base
BASE_IMAGE_VERSION:= $(shell cat ${BASE_IMAGE_NAME}/version.txt)

LAMBDA_IMAGE_NAME=fin-scrap-lambda
LAMBDA_REPO_NAME=fin-scrap-lambda
LAMBDA_IMAGE_VERSION := $(shell cat ${LAMBDA_IMAGE_NAME}/version.txt)
LAMBDA_FUNCTION_NAME=fin-scrap

auth:
aws ecr get-login-password \
--region ${AWS_DEFAULT_REGION} | docker login --username AWS \
--password-stdin ${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com

create-ecr-base:
aws ecr create-repository \
--repository-name ${BASE_REPO_NAME} \
--image-scanning-configuration scanOnPush=true \
--image-tag-mutability MUTABLE \
--region ${AWS_DEFAULT_REGION}

create-ecr-lambda:
aws ecr create-repository \
--repository-name ${LAMBDA_REPO_NAME} \
--image-scanning-configuration scanOnPush=true \
--image-tag-mutability MUTABLE \
--region ${AWS_DEFAULT_REGION}

build-base:
cd ${BASE_IMAGE_NAME} && \
docker build -t ${BASE_IMAGE_NAME}:test -t ${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION} .

build-lambda:
cd ${LAMBDA_IMAGE_NAME} && \
docker build -t ${LAMBDA_IMAGE_NAME}:test -t ${LAMBDA_IMAGE_NAME}:${LAMBDA_IMAGE_VERSION} .

build-all: build-base build-lambda

push-docker-base:
cd ${BASE_IMAGE_NAME} && \
docker tag ${BASE_IMAGE_NAME}:test \
${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${BASE_REPO_NAME}:latest && \
docker tag ${BASE_IMAGE_NAME}:${BASE_IMAGE_VERSION} \
${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${BASE_REPO_NAME}:${BASE_IMAGE_VERSION} && \
docker push ${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${BASE_REPO_NAME} --all-tags

push-docker-lambda:
cd ${LAMBDA_IMAGE_NAME} && \
docker tag ${LAMBDA_IMAGE_NAME}:test \
${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${LAMBDA_REPO_NAME}:latest
docker tag ${LAMBDA_IMAGE_NAME}:${LAMBDA_IMAGE_VERSION} \
${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${LAMBDA_REPO_NAME}:${LAMBDA_IMAGE_VERSION}
docker push ${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${LAMBDA_REPO_NAME} --all-tags

push-docker-all: push-docker-base push-docker-lambda

update-lambda:
aws lambda update-function-code \
--function-name ${LAMBDA_FUNCTION_NAME} \
--image-uri ${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${LAMBDA_REPO_NAME}:latest

create-lambda:
aws lambda create-function \
--function-name ${LAMBDA_FUNCTION_NAME} \
--package-type Image \
--code ImageUri=${AWS_ACCOUNT}.dkr.ecr.${AWS_DEFAULT_REGION}.amazonaws.com/${LAMBDA_REPO_NAME}:latest \
--role arn:aws:iam::${AWS_ACCOUNT}:role/lambda-apigateway-role

# Use only if there are issues to refresh lambda docker image
remove:
docker image rm ${LAMBDA_IMAGE_NAME}:test

run:
aws lambda invoke --function-name ${LAMBDA_FUNCTION_NAME} response.json

all: auth build-all push-docker-all update-lambda

force-update: remove all

# First time setup
# Make sure that IAM role for lambda is created
setup: auth create-ecr-base create-ecr-lambda build-all push-docker-all create-lambda
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions examples/docker/python-3.9-base/Makefile

This file was deleted.

53 changes: 0 additions & 53 deletions examples/docker/python-3.9/Makefile

This file was deleted.

0 comments on commit ab547e5

Please sign in to comment.