Skip to content

Commit

Permalink
refactor: simplify build script
Browse files Browse the repository at this point in the history
  • Loading branch information
rashed091 committed Jun 9, 2024
1 parent a489283 commit cec2692
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ tag: build
push: tag
docker image push $(DOCKER_HUB_REPO)/$(APP_NAME):latest

multi:
./build.sh

testrun:
docker container run --name $(APP_NAME) \
--rm \
Expand All @@ -76,3 +73,6 @@ remove:

list:
docker container ls --all

multiplatform:
./build.sh
41 changes: 15 additions & 26 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ DB_CONTAINER_NAME=$(rg --no-filename --color never 'DATABASE_CONTAINER_NAME=*' .
GIT_REPOSITORY=$(basename `git rev-parse --show-toplevel`)
GIT_BRANCH=$(git branch --show-current)
GIT_COMMIT_SHA=$(git rev-parse HEAD)
GITHUB_WORKFLOW="n/a"
GITHUB_RUN_ID=0
GITHUB_RUN_NUMBER=0
GIT_TAG="latest"

DOCKER_HUB_REPO=mrasheduzzaman
Expand All @@ -24,30 +21,22 @@ PLATFORMS="linux/amd64,linux/arm64"

#Create a new builder instance
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_create.md
docker buildx create --name multiarchcontainerrust --use
docker buildx use multi-platform-builder

docker buildx inspect --bootstrap

#Start a build
#https://github.com/docker/buildx/blob/master/docs/reference/buildx_build.md

docker buildx build \
--tag $IMAGE_NAME \
--label "GITHUB_RUN_ID=$GITHUB_RUN_ID" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--build-arg APP_NAME=$APP_NAME \
--build-arg PORT=$PORT \
--build-arg GIT_REPOSITORY=$GIT_REPOSITORY \
--build-arg GIT_BRANCH=$GIT_BRANCH \
--build-arg GIT_COMMIT=$GIT_COMMIT_SHA \
--build-arg GIT_TAG=$GIT_TAG \
--build-arg GITHUB_WORKFLOW=$GITHUB_WORKFLOW \
--build-arg GITHUB_RUN_ID=$GITHUB_RUN_ID \
--build-arg GITHUB_RUN_NUMBER=$GITHUB_RUN_NUMBER \
--platform $PLATFORMS \
--push \
--output type=docker \
.

#Preview matching images
#https://docs.docker.com/engine/reference/commandline/images/
docker images $GIT_REPOSITORY

docker buildx stop multiarchcontainerrust
--label "GIT_BRANCH=$GIT_BRANCH" \
--label "IMAGE_NAME=$IMAGE_NAME" \
--label "IMAGE_VERSION=$GIT_COMMIT_SHA" \
--label "GIT_REPOSITORY=$GIT_REPOSITORY" \
--build-arg APP_NAME=$(APP_NAME) \
--build-arg PORT=$(PORT) \
--platform $PLATFORMS \
--output "type=image,push=true" \
--tag $IMAGE_NAME --push .

docker buildx stop multi-platform-builder

0 comments on commit cec2692

Please sign in to comment.