This post was translated from Korean into English by AI.
I created a Docker build script that is useful for building small projects.
Usage
Create a build script like the one below.
#!/bin/bash
shopt -s expand_aliases
alias build='curl -sSL l.ist.sh/b | node - build'
# Build images
export BACKEND_IMAGE=`build backend se.ction.link/blog-backend`
export FRONTEND_IMAGE=`build frontend se.ction.link/blog-frontend`
# Deploy with envsubst
cat kubernetes/resources.yaml | envsubst | kubectl apply -f -
How it works
shopt -s expand_aliasesenables aliases.alias build='curl -sSL l.ist.sh/b | node - build'creates thebuildcommand. This command retrieves the build script from my personal server and runs it.- The
build <directory> <registry>command works as follows:- It reads every file in the
directorydirectory and calculates a hash. - It uses the directory hash as the tag to create the image name.
- It checks the automatically generated cache under the
tmpdirectory to determine whether the image exists. - If the image does not exist, it builds the image with
docker buildx. - It pushes the image.
- It writes the image name to stdout.
- It reads every file in the
- It reads the Kubernetes resource file and substitutes environment variables using envsubst.
- It deploys the substituted file with kubectl.