Skip to content

Commit 216024c

Browse files
Update tooling
More justfile recipes/less hard-coding, bootstrap file with case statement, and placeholder version file
1 parent 0352ef8 commit 216024c

File tree

4 files changed

+106
-34
lines changed

4 files changed

+106
-34
lines changed

.env.example

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
REGISTRY_URL=1234.dkr.ecr.us-east-1.amazonaws.com
2+
APP_NAME=appname
3+
TAG=latest
4+
EMAIL=thisismysingingvoice@acme.co
5+
URL=https://acme.co
6+
USER=apiuser
7+
PASSWORD=apiuserpassword
8+
VERBOSE=false
9+
OVERWRITE=true
10+
PORT=80

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.2.0

bootstrap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
3+
# SOURCES:
4+
# https://gist.github.com/mpneuried/0594963ad38e68917ef189b4e6a269db
5+
6+
# INSTALL
7+
# - copy the files .env, VERSION and justfile to your repo
8+
# - replace the vars in .env
9+
# - define the version script
10+
11+
# case statement to choose input arguments
12+
case "$1" in
13+
build-nc)
14+
# Build the container
15+
just build-nc
16+
;;
17+
release)
18+
# Build and publish the container
19+
just release
20+
;;
21+
run)
22+
# Run the docker container; remove upon exit
23+
just run
24+
;;
25+
start)
26+
# Build and run the docker-compose container
27+
just start
28+
;;
29+
stop)
30+
# Stop the running docker-compose container
31+
just stop
32+
;;
33+
*)
34+
echo $"Usage: $0 {build-nc|release|run|start|stop}"
35+
exit 1
36+
esac

justfile

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
# See https://just.systems/man/en
2-
3-
# positional args
4-
# * NOTE: unable to reuse recipe name (e.g., start/stop); prefix recipes with `@`
5-
# set positional-arguments := true
1+
# https://just.systems/man/en
62

73
# load .env
8-
set dotenv-load := true
4+
set dotenv-load
95

106
# set env var
11-
export APP := "compose_image_name"
12-
export CPU := "2"
13-
export MEM := "2048"
14-
export NS := "default"
15-
export PROF := "minikube"
16-
export SHELL := "/bin/bash"
17-
export TAG := "latest"
7+
export APP := "compose_image_name"
8+
export CPU := "2"
9+
export IMAGE := `echo ${REGISTRY_URL}/it
10+
export MEM := "2048"
11+
export NS := "default"
12+
export PROF := "minikube"
13+
export SHELL := "/bin/bash"
14+
VERSION := `cat VERSION`
1815

1916
# x86_64/arm64
2017
arch := `uname -m`
@@ -42,38 +39,55 @@ start-devspace:
4239
stop-devspace:
4340
minikube stop -p {{PROF}}
4441

45-
# [docker] build locally or on intel box
42+
# [docker] build locally
4643
build:
47-
#!/usr/bin/env bash
48-
set -euxo pipefail
44+
#!/usr/bin/env bash
45+
# set -euxo pipefail
4946

50-
if [[ {{arch}} == "arm64" ]]; then
51-
docker build -f Dockerfile -t {{APP}}:{{TAG}} --build-arg CHIPSET_ARCH=aarch64-linux-gnu .
52-
else
53-
docker buildx build -f Dockerfile --progress=plain -t {{APP}}:{{TAG}} --build-arg CHIPSET_ARCH=x86_64-linux-gnu --load .
54-
fi
47+
echo "building ${APP_NAME}:${TAG}"
48+
49+
if [[ {{arch}} == "arm64" ]]; then
50+
docker build -f Dockerfile -t it/${APP_NAME}:${TAG} --build-arg CHIPSET_ARCH=aarch64-linux-gnu .
51+
else
52+
docker build -f Dockerfile -t it/${APP_NAME}:${TAG} --build-arg CHIPSET_ARCH=x86_64-linux-gnu .
53+
fi
54+
55+
echo "created tag it/${APP_NAME}:${TAG} {{IMAGE}}/${APP_NAME}:${TAG}"
5556

57+
# TODO: QA
5658
# [docker] intel build
5759
buildx:
58-
docker buildx build -f Dockerfile --progress=plain -t {{TAG}} --build-arg CHIPSET_ARCH=x86_64-linux-gnu --load .
60+
docker buildx build -f Dockerfile --progress=plain -t ${TAG} --build-arg CHIPSET_ARCH=x86_64-linux-gnu --load .
5961

6062
# [docker] build w/docker-compose defaults
61-
build-clean:
62-
#!/usr/bin/env bash
63-
set -euxo pipefail
63+
build-nc:
64+
#!/usr/bin/env bash
65+
# set -euxo pipefail
6466

65-
if [[ {{arch}} == "arm64" ]]; then
66-
docker-compose build --pull --no-cache --build-arg CHIPSET_ARCH=aarch64-linux-gnu
67-
else
68-
docker-compose build --pull --no-cache --build-arg CHIPSET_ARCH=x86_64-linux-gnu
69-
fi
67+
if [[ {{arch}} == "arm64" ]]; then
68+
docker-compose build --pull --no-cache --build-arg CHIPSET_ARCH=aarch64-linux-gnu
69+
else
70+
docker-compose build --pull --no-cache --build-arg CHIPSET_ARCH=x86_64-linux-gnu
71+
fi
7072

7173
# [docker] pull latest image
7274
pull:
73-
docker pull python:3.10-slim-buster
75+
docker pull {{IMAGE}}/${APP_NAME}:${TAG}
76+
77+
# [docker] run local image
78+
run: pull
79+
docker run -it --rm -v $(pwd):/app {{IMAGE}}/${APP_NAME}:${TAG} {{SHELL}}
80+
81+
# [docker] push latest image to ecr
82+
release:
83+
#!/usr/bin/env bash
84+
# set -euxo pipefail
85+
86+
AWS_DEFAULT_PROFILE=bastion.use1 aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${REGISTRY_URL}
87+
docker push {{IMAGE}}/${APP_NAME}:${TAG}
7488

7589
# [docker] start docker-compose container
76-
up:
90+
start:
7791
docker-compose up -d
7892

7993
# [docker] ssh into container
@@ -85,5 +99,16 @@ stop:
8599
docker-compose stop
86100

87101
# [docker] remove docker-compose container(s) and networks
88-
down:
89-
docker-compose stop && docker-compose down --remove-orphans
102+
down: stop
103+
docker-compose down --remove-orphans
104+
105+
# [docker] tag image as latest
106+
tag-latest:
107+
@echo "create tag it/${APP_NAME}:${TAG} {{IMAGE}}/${APP_NAME}:${TAG}"
108+
docker tag it/${APP_NAME}:${TAG} {{IMAGE}}/${APP_NAME}:${TAG}
109+
110+
# TODO: QA
111+
# [docker] tag image from VERSION file
112+
tag-version:
113+
@echo "create tag it/${APP_NAME}:{{VERSION}} {{IMAGE}}/${APP_NAME}:${TAG}"
114+
docker tag it/${APP_NAME}:{{VERSION}} {{IMAGE}}/${APP_NAME}:${TAG}

0 commit comments

Comments
 (0)