Skip to content

Commit

Permalink
Regenerate static files
Browse files Browse the repository at this point in the history
  • Loading branch information
j616 committed Nov 2, 2023
1 parent aacfbf5 commit 446fc51
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions static-commontooling/make/include/ecr_docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,49 @@ ifneq ($(findstring public.ecr.aws,$(DOCKER_REPO)),)
ECR_HOST:=$(word 1,$(subst /, ,$(DOCKER_REPO)))
# There is no ECS Public endpoint in eu-west-1, which is why us-east-1 is used instead
ECR_LOGIN_REGION:=us-east-1
else
else # ifneq ($(findstring public.ecr.aws,$(DOCKER_REPO)),)
ifneq ($(findstring dkr.ecr,$(DOCKER_REPO)),)
# ECR (Private) registry
IS_ECR_REGISTRY:=true
ECR_COMMAND:=ecr
ECR_HOST:=$(word 1,$(subst /, ,$(DOCKER_REPO)))
ECR_LOGIN_REGION:=$(word 4,$(subst ., ,$(DOCKER_REPO)))
else
else # ifneq ($(findstring dkr.ecr,$(DOCKER_REPO)),)
IS_ECR_REGISTRY:=false
endif
endif
endif # ifneq ($(findstring dkr.ecr,$(DOCKER_REPO)),)
endif # ifneq ($(findstring public.ecr.aws,$(DOCKER_REPO)),)



ifeq (${IS_ECR_REGISTRY},true)
ECR_REPO_NAME:=cloudfit/${MODNAME}

ifeq (${GITHUB_ACTIONS},true)
# On GitHub actions, the AWS credentials doesn't exist
# But aws-cli is available and has access to creds via other means
CREATE_ECR_REPO:=aws ${ECR_COMMAND} create-repository --repository-name ${ECR_REPO_NAME} --region ${ECR_LOGIN_REGION}
ECR_LOGIN:=
ECR_LOGOUT:=

# On GitHub Actions, ECR login and logout is handled by the workflow
define ecr_docker_push
${CREATE_ECR_REPO} || true
docker push $(1)
endef

else # ifeq (${GITHUB_ACTIONS},true)

CLOUDFIT_AWS_IMAGE:=ap-docker.artifactory.labs.bbc/cloudfit/aws:latest

ifneq ($(AWS_SHARED_CREDENTIALS_FILE),)
AWS_DOCKER_ARGS:=-v ${AWS_SHARED_CREDENTIALS_FILE}:/root/.aws/config ${CLOUDFIT_AWS_IMAGE}
else
else # ifneq ($(AWS_SHARED_CREDENTIALS_FILE),)
AWS_DOCKER_ARGS:=-v ${FORGE_CERT}:/run/secrets/forgecert:ro ${CLOUDFIT_AWS_IMAGE}
endif
endif # ifneq ($(AWS_SHARED_CREDENTIALS_FILE),)

CREATE_ECR_REPO:=docker run --rm ${AWS_DOCKER_ARGS} ${ECR_COMMAND} create-repository --repository-name ${ECR_REPO_NAME} --region ${ECR_LOGIN_REGION}
ECR_LOGIN:=docker run --rm -i ${AWS_DOCKER_ARGS} ${ECR_COMMAND} get-login-password --region ${ECR_LOGIN_REGION} | docker login --username AWS --password-stdin ${ECR_HOST}
ECR_LOGOUT:=docker logout ${ECR_HOST}
endif


# Log into the ECR registry before pushing, and then log out
# Create the AWS ECR repo because ECR doesn't support create on push - see https://github.com/aws/containers-roadmap/issues/853
Expand All @@ -52,3 +68,7 @@ define ecr_docker_push
${ECR_LOGOUT}; \
exit $$res
endef

endif # ifeq (${GITHUB_ACTIONS},true)
endif # ifeq (${IS_ECR_REGISTRY},true)

0 comments on commit 446fc51

Please sign in to comment.