Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoAssignmentChecker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Dojo Project (HES-SO)
Projects
Pipelines
DojoAssignmentChecker
Commits
4bf8fc95
Commit
4bf8fc95
authored
7 months ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
Add deploy to Docker Hub script
parent
4e1cde90
No related branches found
No related tags found
No related merge requests found
Pipeline
#34763
passed
7 months ago
Stage: code_quality
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
deploy_on_dockerhub.sh
+135
-0
135 additions, 0 deletions
deploy_on_dockerhub.sh
with
135 additions
and
0 deletions
deploy_on_dockerhub.sh
0 → 100755
+
135
−
0
View file @
4bf8fc95
#!/bin/bash
# Define color codes
RED
=
'\033[0;31m'
GREEN
=
'\033[0;32m'
YELLOW
=
'\033[1;33m'
NC
=
'\033[0m'
# No Color
DOCKERFILE
=
Dockerfile_AssignmentChecker
PROJECT_FOLDER
=
AssignmentChecker
test_if_command_unsuccessful
()
{
local
status
=
$1
local
title
=
$2
local
text_if_failed
=
$3
if
[
"
$status
"
-ne
0
]
;
then
echo
-e
"
${
title
}
:
${
RED
}${
text_if_failed
}
:
$status
${
NC
}
\n
"
exit
1
fi
}
##########################################################
# Function to prompt for input if not provided
prompt_if_empty
()
{
local
var_name
=
$1
local
prompt_message
=
$2
local
var_value
=
${
!var_name
}
if
[
-z
"
$var_value
"
]
;
then
read
-p
"
$prompt_message
: "
var_value
export
"
$var_name
"
=
"
$var_value
"
fi
}
# Parse parameters
while
[
"
$1
"
!=
""
]
;
do
case
$1
in
--dockerhub-user
)
shift
DOCKER_REGISTRY_USER
=
$1
;;
--dockerhub-password
)
shift
DOCKER_REGISTRY_PASSWORD
=
$1
;;
--dockerhub-repo
)
shift
DOCKER_REGISTRY_IMAGE
=
$1
;;
--backend-url
)
shift
API_URL
=
$1
;;
*
)
echo
-e
"
${
RED
}
Invalid parameter:
$1
${
NC
}
"
exit
1
esac
shift
done
# Prompt for values if not provided
prompt_if_empty
"DOCKER_REGISTRY_USER"
"Docker Hub user"
prompt_if_empty
"DOCKER_REGISTRY_PASSWORD"
"Docker Hub password"
prompt_if_empty
"DOCKER_REGISTRY_IMAGE"
"Docker Hub repository"
prompt_if_empty
"API_URL"
"Backend url"
##########################################################
# Function to check if a command exists
check_dependency
()
{
local
cmd
=
$1
if
!
command
-v
$cmd
&> /dev/null
;
then
echo
-e
"
${
RED
}
Error:
$cmd
is not installed.
${
NC
}
"
exit
1
fi
}
# Check for dependencies
echo
-e
"Dependencies:
${
YELLOW
}
Checking...
${
NC
}
"
check_dependency jq
check_dependency docker
check_dependency
sed
echo
-e
"Dependencies:
${
GREEN
}
OK
${
NC
}
\n
"
VERSION
=
$(
jq
-r
.version
$PROJECT_FOLDER
/package.json
)
CONTAINER_IMAGE
=
$DOCKER_REGISTRY_IMAGE
:
$VERSION
##########################################################
# Login to Docker Hub
echo
-e
"Docker Hub:
${
YELLOW
}
Login in...
${
NC
}
"
echo
"
$DOCKER_REGISTRY_PASSWORD
"
| docker login
-u
"
$DOCKER_REGISTRY_USER
"
--password-stdin
"
$DOCKER_REGISTRY
"
>
/dev/null
test_if_command_unsuccessful
$?
"Docker Hub"
"FAILED to login in"
echo
-e
"Docker Hub:
${
GREEN
}
Logged in
${
NC
}
\n
"
##########################################################
echo
-e
"Project files:
${
YELLOW
}
Configuring...
${
NC
}
"
(
cd
$PROJECT_FOLDER
||
exit
1
sed
-i
-r
"s/
\{\{
VERSION
\}\}
/
${
VERSION
}
/g"
src/app.ts 2> /dev/null
if
[
$?
-ne
0
]
;
then
# If on macOS
sed
-i
-r
"s/{{VERSION}}/
${
VERSION
}
/g"
src/app.ts 2> /dev/null
fi
sed
-i
-r
"s/(DOTENV_KEY[ ]*:[ ]*[
\'\"\`
])[^'
\"\`
]*([
\'\"\`
])([ ]*
\,
)?//g"
src/init.ts
sed
-i
-r
"s/,[
\ \n
]*
\}
/
\}
/g"
src/init.ts
# Write the content to the file
cat
<<
EOL
> ".env"
##################### App env vars
API_URL=
${
API_URL
}
DOCKERHUB_ASSIGNMENT_CHECKER_REPOSITORY=
${
DOCKER_REGISTRY_IMAGE
}
EOL
)
echo
-e
"Project files:
${
GREEN
}
Configured
${
NC
}
\n
"
##########################################################
echo
-e
"Docker:
${
YELLOW
}
Building/Uploading to Docker Hub...
${
NC
}
"
docker buildx create
--use
--platform
=
linux/amd64
>
/dev/null 2> /dev/null
test_if_command_unsuccessful
$?
"Docker"
"FAILED to initialize builder"
docker buildx build
--platform
=
linux/amd64
--file
$DOCKERFILE
--push
--tag
"
$CONTAINER_IMAGE
"
.
>
/dev/null 2> /dev/null
test_if_command_unsuccessful
$?
"Docker"
"FAILED to build"
docker buildx imagetools create
"
$CONTAINER_IMAGE
"
--tag
"
$DOCKER_REGISTRY_IMAGE
"
:latest
>
/dev/null 2> /dev/null
test_if_command_unsuccessful
$?
"Docker"
"FAILED to set latest tag"
echo
-e
"Docker:
${
GREEN
}
Uploaded to Docker Hub
${
NC
}
\n
"
\ No newline at end of file
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