Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
1
1-tracer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SO2
1-tracer
Commits
4bb42f74
Commit
4bb42f74
authored
2 years ago
by
Baruta Daniel Mihail
Browse files
Options
Downloads
Patches
Plain Diff
local.sh docker image build, push and test capability
parent
2ba7f027
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
local.sh
+198
-14
198 additions, 14 deletions
local.sh
with
198 additions
and
14 deletions
local.sh
+
198
−
14
View file @
4bb42f74
...
@@ -2,12 +2,28 @@
...
@@ -2,12 +2,28 @@
cd
"
$(
dirname
"
$0
"
)
"
||
exit
1
cd
"
$(
dirname
"
$0
"
)
"
||
exit
1
#=============================================================================
#================================= CONSTANTS =================================
#=============================================================================
RED
=
'\033[0;31m'
NC
=
'\033[0m'
DEFAULT_IMAGE_NAME
=
"
$(
basename
"
$(
pwd
)
"
)
"
DEFAULT_TAG
=
'latest'
DEFAULT_REGISTRY
=
'registry.gitlab.cs.pub.ro'
#=============================================================================
#=============================================================================
#=================================== UTILS ===================================
#=================================== UTILS ===================================
#=============================================================================
#=============================================================================
LOG_INFO
()
{
LOG_INFO
()
{
echo
"[INFO]
$1
"
echo
-e
"[
$(
date
+%F_%T
)
] [INFO]
$1
"
}
LOG_FATAL
()
{
echo
-e
"[
$(
date
+%F_%T
)
] [
${
RED
}
FATAL
${
NC
}
]
$1
"
exit
1
}
}
#=============================================================================
#=============================================================================
...
@@ -17,27 +33,185 @@ LOG_INFO() {
...
@@ -17,27 +33,185 @@ LOG_INFO() {
print_help
()
{
print_help
()
{
echo
"Usage:"
echo
"Usage:"
echo
""
echo
""
echo
"local.sh
[-h|--help] [--remove_image] [argumets_for_checker]
"
echo
"local.sh
checker|docker|-h|--help
"
echo
""
echo
""
echo
" --remove_image - remove the checker's docker image after the run"
echo
" docker - runs docker commands to build, test or push an image made of this repo"
echo
" checker - runs the checker"
echo
" -h|--help - prints this message"
echo
" -h|--help - prints this message"
echo
""
echo
"local.sh docker build [--image_name <image_name>] [--tag <tag>] [--registry <registry>]"
echo
""
echo
" --image_name <image_name> - the name of the image (default: current directory name)"
echo
" --tag <tag> - the tag of the image (default: 'latest')"
echo
" --registry <registry> - the registry in which the image will be pushed (default: 'registry.gitlab.cs.pub.ro')"
echo
""
echo
"local.sh docker push --user <user> --token <token> [--image_name <image_name>] [--tag <tag>] [--registry <registry>]"
echo
""
echo
" --image_name <image_name> - the name of the image (default: current directory name)"
echo
" --tag <tag> - the tag of the image (default: 'latest')"
echo
" --registry <registry> - the registry in which the image will be pushed (default: 'registry.gitlab.cs.pub.ro')"
echo
" --user <registry> - username for the repository registry"
echo
" --token <registry> - the registry in which the image will be pushed (default: 'registry.gitlab.cs.pub.ro')"
echo
""
echo
"local.sh docker test [--full_image_name <full_image_name>] [argumets_for_checker]"
echo
""
echo
" --full_image_name <full_image_name> - the full name of the image (default: registry.gitlab.cs.pub.ro/<current_directory_name>:latest)"
echo
" argumets_for_checker - list of space separated arguments to be passed to the checker"
echo
""
echo
"local.sh docker interactive [--full_image_name <full_image_name>] [--use_executable <executbale>]"
echo
""
echo
" --full_image_name <full_image_name> - the full name of the image (default: registry.gitlab.cs.pub.ro/<current_directory_name>:latest)"
echo
" --use_executable <executable> - command to run inside the container (default: /bin/bash)"
echo
""
echo
"local.sh checker [--remove_image] [argumets_for_checker]"
echo
""
echo
" --remove_image - remove the checker's docker image after the run"
echo
" argumets_for_checker - list of space separated arguments to be passed to the checker"
echo
" argumets_for_checker - list of space separated arguments to be passed to the checker"
echo
""
echo
""
}
}
main
()
{
docker_build
()
{
local
image_name
=
"
$DEFAULT_IMAGE_NAME
"
local
tag
=
"
$DEFAULT_TAG
"
local
registry
=
"
$DEFAULT_REGISTRY
"
while
[[
$#
-gt
0
]]
;
do
case
$1
in
--image_name
)
shift
image_name
=
"
$1
"
;;
--tag
)
shift
tag
=
"
$1
"
;;
--registry
)
shift
registry
=
"
$1
"
;;
esac
shift
done
LOG_INFO
"Building Docker image..."
docker image build
-t
"
${
registry
}
/
${
image_name
}
:
${
tag
}
"
.
}
docker_push
()
{
local
image_name
=
"
$DEFAULT_IMAGE_NAME
"
local
tag
=
"
$DEFAULT_TAG
"
local
registry
=
"
$DEFAULT_REGISTRY
"
local
user
=
''
local
token
=
''
while
[[
$#
-gt
0
]]
;
do
case
$1
in
--image_name
)
shift
image_name
=
"
$1
"
;;
--tag
)
shift
tag
=
"
$1
"
;;
--registry
)
shift
registry
=
"
$1
"
;;
--user
)
shift
user
=
"
$1
"
;;
--token
)
shift
token
=
"
$1
"
;;
esac
shift
done
[
-z
"
$user
"
]
&&
LOG_FATAL
"No user provided. Push operation will be aborted..."
[
-z
"
$token
"
]
&&
LOG_FATAL
"No token provided. Push operation will be aborted..."
LOG_INFO
"Pushing Docker image..."
docker login
"
${
registry
}
"
-u
"
${
user
}
"
-p
"
${
token
}
"
docker push
"
${
registry
}
/
${
image_name
}
:
${
tag
}
"
}
docker_test
()
{
local
full_image_name
=
"
${
DEFAULT_REGISTRY
}
/
${
DEFAULT_IMAGE_NAME
}
:
${
DEFAULT_TAG
}
"
while
[[
$#
-gt
0
]]
;
do
case
$1
in
--full_image_name
)
shift
full_image_name
=
"
$1
"
;;
esac
shift
done
checker_main
--use_existing_image
"
$full_image_name
"
"
$@
"
}
docker_interactive
()
{
local
full_image_name
=
"
${
DEFAULT_REGISTRY
}
/
${
DEFAULT_IMAGE_NAME
}
:
${
DEFAULT_TAG
}
"
local
executable
=
"/bin/bash"
while
[[
$#
-gt
0
]]
;
do
case
$1
in
--full_image_name
)
shift
full_image_name
=
"
$1
"
;;
--use_executable
)
shift
executable
=
"
$1
"
;;
esac
shift
done
tmpdir
=
"
$(
mktemp
-d
)
"
cp
-R
./
*
"
$tmpdir
"
docker run
--rm
-it
\
--mount
type
=
bind
,source
=
"
$tmpdir
"
,target
=
/build
\
"
$full_image_name
"
"
$executable
"
}
docker_main
()
{
if
[
"
$1
"
=
"build"
]
;
then
shift
docker_build
"
$@
"
elif
[
"
$1
"
=
"push"
]
;
then
shift
docker_push
"
$@
"
elif
[
"
$1
"
=
"test"
]
;
then
shift
docker_test
"
$@
"
elif
[
"
$1
"
=
"interactive"
]
;
then
shift
docker_interactive
"
$@
"
fi
}
checker_main
()
{
local
script_args
=()
local
script_args
=()
local
remove_image
=
''
local
remove_image
=
''
local
image_name
=
''
while
[[
$#
-gt
0
]]
;
do
while
[[
$#
-gt
0
]]
;
do
case
$1
in
case
$1
in
-h
|
--help
)
print_help
exit
0
;;
--remove_image
)
--remove_image
)
remove_image
=
'true'
remove_image
=
'true'
;;
;;
--use_existing_image
)
shift
image_name
=
"
$1
"
;;
*
)
*
)
script_args+
=(
"
$1
"
)
script_args+
=(
"
$1
"
)
;;
;;
...
@@ -45,18 +219,18 @@ main() {
...
@@ -45,18 +219,18 @@ main() {
shift
shift
done
done
image_name
=
"
$(
basename
"
$(
pwd
)
"
)
"
if
[
-z
"
$image_name
"
]
;
then
image_name
=
"
$(
basename
"
$(
pwd
)
"
)
"
LOG_INFO
"Building image..."
docker build
-q
-t
"
$image_name
"
.
LOG_INFO
"Building image..."
docker build
-q
-t
"
$image_name
"
.
fi
tmpdir
=
"
$(
mktemp
-d
)
"
tmpdir
=
"
$(
mktemp
-d
)
"
cp
-R
./
*
"
$tmpdir
"
cp
-R
./
*
"
$tmpdir
"
LOG_INFO
"Running checker..."
LOG_INFO
"Running checker..."
docker run
--rm
\
docker run
--rm
\
--name
"
$image_name
-container"
\
--mount
type
=
bind
,source
=
"
$tmpdir
"
,target
=
/build
\
--mount
type
=
bind
,source
=
"
$tmpdir
"
,target
=
/build
\
"
$image_name
"
/bin/bash /build/checker/checker.sh
"
${
script_args
[@]
}
"
"
$image_name
"
/bin/bash /build/checker/checker.sh
"
${
script_args
[@]
}
"
...
@@ -67,4 +241,14 @@ main() {
...
@@ -67,4 +241,14 @@ main() {
}
}
main
"
$@
"
if
[
"
$1
"
=
"checker"
]
;
then
shift
checker_main
"
$@
"
elif
[
"
$1
"
=
"docker"
]
;
then
shift
docker_main
"
$@
"
elif
[
"
$1
"
=
"-h"
]
||
[
"
$1
"
=
"--help"
]
;
then
print_help
else
print_help
fi
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment