This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7eb5ce
commit 579d4fa
Showing
5 changed files
with
91 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: "docker-update-base-and-push" | ||
|
||
on: | ||
schedule: | ||
- cron: "00 01 * * *" | ||
|
||
jobs: | ||
docker-build-and-push: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: add builder | ||
run: docker run --privileged --rm tonistiigi/binfmt --install all && docker buildx create --use | ||
- name: checkout repository | ||
uses: actions/checkout@v3 | ||
- name: login into repository | ||
run: echo ${{ secrets.DOCKER_REGISTRY_PASSWORD }} | docker login --username ${{ secrets.DOCKER_REGISTRY_USERNAME }} --password-stdin | ||
- name: update base and push | ||
run: ./docker-build.sh --push --update-base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# folders | ||
.idea | ||
.vscode | ||
builds | ||
data-local | ||
node_modules | ||
target | ||
|
||
# files | ||
package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v0.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
variable "BASE_IMAGE_DATE" { | ||
default = "unknown" | ||
} | ||
variable "IMAGE" { | ||
default = "unknown" | ||
} | ||
variable "VERSION" { | ||
default = "v0.0.1" | ||
} | ||
|
||
target "default" { | ||
tags = [ | ||
"madebytimo/nginx:latest", | ||
"madebytimo/nginx:${VERSION}", | ||
"madebytimo/nginx:${VERSION}-base-${BASE_IMAGE_DATE}" | ||
"${IMAGE}:latest", | ||
"${IMAGE}:${VERSION}", | ||
"${IMAGE}:${VERSION}-base-${BASE_IMAGE_DATE}" | ||
] | ||
platforms = [ | ||
"amd64", | ||
"arm64", | ||
"arm", | ||
"arm" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,60 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
BUILD_ARGUMENTS="" | ||
DEPENDENCIES=(docker) | ||
UPDATE_BASE=false | ||
REPOSIITORY_NAME="docker-nginx" | ||
VERSION="" | ||
|
||
# help message | ||
for ARGUMENT in "$@"; do | ||
if [ "$ARGUMENT" == "-h" ] || [ "$ARGUMENT" == "--help" ]; then | ||
echo "usage: $(basename "$0") [ARGUMENT]" | ||
echo "Builds the docker image from the Dockerfile." | ||
echo "ARGUMENT can be" | ||
echo "--push push the build" | ||
echo "--update-base only build if newer base image available." | ||
exit | ||
fi | ||
done | ||
|
||
# check dependencies | ||
for cmd in ${DEPENDENCIES[@]}; do | ||
if [[ -z "$(command -v $cmd)" ]]; then | ||
echo "$cmd is missing!" | ||
exit 1 | ||
fi | ||
done | ||
|
||
# check arguments | ||
while [[ -n "$1" ]]; do | ||
if [[ "$1" = "--update-base" ]]; then | ||
UPDATE_BASE=true | ||
elif [[ "$1" = "--push" ]]; then | ||
BUILD_ARGUMENTS+=" --push" | ||
else | ||
echo "Unknown argument: \"$1\"" | ||
exit 1 | ||
fi | ||
shift | ||
done | ||
|
||
BASE_IMAGE="$(tac Dockerfile | grep --max-count=1 "FROM" | cut -d" " -f2)" | ||
docker pull "$BASE_IMAGE" | ||
BASE_IMAGE_DATE="$(docker image inspect --format="{{ .Created }}" "$BASE_IMAGE" | cut -d "T" -f1)" | ||
echo "Base is $BASE_IMAGE from $BASE_IMAGE_DATE" | ||
export BASE_IMAGE BASE_IMAGE_DATE | ||
docker buildx bake -f docker-bake.hcl $@ | ||
echo "Base image is $BASE_IMAGE from $BASE_IMAGE_DATE" | ||
IMAGE="madebytimo/${REPOSIITORY_NAME#docker-}" | ||
if [[ "$UPDATE_BASE" == true ]]; then | ||
docker pull "$IMAGE" | ||
PUSHED_IMAGE_DATE="$(docker image inspect --format="{{ .Created }}" "$IMAGE" | cut -d "T" -f1)" | ||
echo "Last pushed image is from $PUSHED_IMAGE_DATE" | ||
if [[ "$BASE_IMAGE_DATE" < "$PUSHED_IMAGE_DATE" ]]; then | ||
echo "Used base image is up to date" | ||
exit; | ||
fi | ||
fi | ||
VERSION="$(cat Version.txt)" | ||
|
||
export BASE_IMAGE BASE_IMAGE_DATE IMAGE VERSION | ||
docker buildx bake --file docker-bake.hcl $BUILD_ARGUMENTS |