Skip to content

Commit

Permalink
chore: get-version.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
levy9527 authored Apr 18, 2024
1 parent d71e887 commit 7b508c1
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/devops/docker-build-and-push-script.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ docker --config ~/.project1 pull registry.example.com/project1
docker --config ~/.project2 pull registry.example.com/project2
```

## get-version.sh
```shell
#!/bin/sh

# Get the current datetime in the desired format (YYYY-MM-DD-HHMM)
CURRENT_DATETIME=$(TZ="Asia/Shanghai" date +'%Y_%m_%d_%H_%M')

# Get the abbreviated Git commit hash
GIT_COMMIT=$(git rev-parse --short HEAD)

# Combine the datetime and Git commit hash to generate the tag
TAG="${CURRENT_DATETIME}-${GIT_COMMIT}"

# Print the generated tag
echo "${TAG}"
```

## build-image.sh
support command:
```shell
Expand All @@ -41,7 +58,7 @@ REGISTRY_URL=https://$REGISTRY

# 镜像名称和标签
IMAGE=$REGISTRY/xxx/$(basename "$(pwd)")
IMAGE_TAG=$(cat VERSION)
IMAGE_TAG=$(./get-version.sh)

# Dockerfile文件位置
DOCKERFILE_PATH=./Dockerfile
Expand Down

0 comments on commit 7b508c1

Please sign in to comment.