Skip to content

Commit 25764d1

Browse files
authored
Merge pull request #2 from JayJamieson/feat/slim-image-creation-and-push
added slim image creation to build script
2 parents f93a089 + 2f0a46b commit 25764d1

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ Usage: ./build_image.sh --account-id ID --region REGION --repo-name NAME [--tag
4141
--tag Image tag override; if omitted, use latest Git tag on HEAD
4242
```
4343
44+
If you want to create and push smaller slim images then please install [slimtoolkit/slim](https://github.com/slimtoolkit/slim). You can then optionally pass `--slim-image` to minify images and push to ECR.
45+
4446
## Deploy
4547
4648
Create a `terraform.tfvars` file inside infrastructure folder and fill out required variables.

build_image.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ ACCOUNT_ID=""
2424
REGION=""
2525
REPO_NAME=""
2626
TAG=""
27+
WITH_SLIM=false
2728

2829
while [[ $# -gt 0 ]]; do
2930
case "$1" in
3031
--account-id) ACCOUNT_ID="$2"; shift 2 ;;
3132
--region) REGION="$2"; shift 2 ;;
3233
--repo-name) REPO_NAME="$2"; shift 2 ;;
3334
--tag) TAG="$2"; shift 2 ;;
35+
--slim-image) WITH_SLIM=true; shift ;;
3436
-h|--help) usage ;;
3537
*) echo -e "${RED}Unknown option: $1${NC}" >&2; usage ;;
3638
esac
@@ -68,11 +70,19 @@ docker tag "${IMAGE_REPO}" "${IMAGE_REPO}:latest" >&2
6870
echo -e "${GREEN}Tagging succeeded.${NC}" >&2
6971

7072
echo -e "${YELLOW}Pushing ${IMAGE_URI}${NC}" >&2
71-
docker push "${IMAGE_URI}" >&2
72-
echo -e "${GREEN}Pushed ${IMAGE_URI}.${NC}" >&2
73+
docker push --quiet "${IMAGE_URI}" >&2
74+
75+
if $WITH_SLIM; then
76+
echo -e "${YELLOW}Creating slim image…${NC}" >&2
77+
slim --quiet build --http-probe=false --continue-after=1 --target "${IMAGE_REPO}:latest" --tag "${IMAGE_REPO}:slim-${IMAGE_TAG}"
78+
docker push --quiet "${IMAGE_REPO}:slim-${IMAGE_TAG}" >&2
79+
echo -e "${GREEN}Pushed ${IMAGE_REPO}:slim.${NC}" >&2
80+
fi
7381

82+
echo -e "${GREEN}Pushed ${IMAGE_URI}.${NC}" >&2
7483
echo -e "${YELLOW}Pushing latest tag…${NC}" >&2
75-
docker push "${IMAGE_REPO}:latest" >&2
84+
85+
docker push --quiet "${IMAGE_REPO}:latest" >&2
7686
echo -e "${GREEN}Pushed latest tag.${NC}" >&2
7787

7888
jq -n --arg uri "$IMAGE_URI" '{"image_uri":$uri}'

create-ecr.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ while [[ $# -gt 0 ]]; do
3030
--repo-name) REPO_NAME="$2"; shift 2 ;;
3131
--region) REGION="$2"; shift 2 ;;
3232
--account-id) ACCOUNT_ID="$2"; shift 2 ;;
33-
--auth-only) AUTH_ONLY=true; shift ;;
33+
--auth-only) AUTH_ONLY=true; shift ;;
3434
-h|--help) usage ;;
3535
*) echo -e "${RED}Unknown option: $1${NC}" >&2; usage ;;
3636
esac

0 commit comments

Comments
 (0)