mirror of
https://github.com/Direct-Dev-Ru/go-lcg.git
synced 2025-11-16 01:29:55 +00:00
release v1.0.1
This commit is contained in:
41
shell-code/build-to-dockerhub.sh
Normal file
41
shell-code/build-to-dockerhub.sh
Normal file
@@ -0,0 +1,41 @@
|
||||
#!/bin/bash
|
||||
|
||||
REPO=kuznetcovay/go-ansible-vault
|
||||
VERSION=$1
|
||||
if [ -z "$VERSION" ]; then
|
||||
VERSION=v1.0.8
|
||||
fi
|
||||
BRANCH=main
|
||||
|
||||
echo ${VERSION} > VERSION.txt
|
||||
export GOCACHE="${HOME}/.cache/go-build"
|
||||
|
||||
# Save the current branch
|
||||
CURRENT_BRANCH=$(git branch --show-current)
|
||||
|
||||
# Function to restore the original branch
|
||||
function restore_branch {
|
||||
echo "Restoring original branch: ${CURRENT_BRANCH}"
|
||||
git checkout "${CURRENT_BRANCH}"
|
||||
}
|
||||
|
||||
# Check if the current branch is different from the target branch
|
||||
if [ "$CURRENT_BRANCH" != "$BRANCH" ]; then
|
||||
# Set a trap to restore the branch on exit
|
||||
trap restore_branch EXIT
|
||||
echo "Switching to branch: ${BRANCH}"
|
||||
git checkout ${BRANCH}
|
||||
fi
|
||||
|
||||
# Run go tests
|
||||
if ! go test -v -run=^Test; then
|
||||
echo "Tests failed. Exiting..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Push multi-platform images
|
||||
docker buildx build --push --platform linux/amd64,linux/arm64 -t ${REPO}:${VERSION} . ||
|
||||
{
|
||||
echo "docker buildx build --push failed. Exiting with code 1."
|
||||
exit 1
|
||||
}
|
||||
Reference in New Issue
Block a user