-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ALS-5056] Create Jenkins job for building and deploying services
- Create a job that: - Finds a service in the pic-sure-services repo - Creates a resource uuid for it - Adds that uuid to its .env - Moves it to the docker-compose services dir - Tells docker to build and deploy it - Also create the mount point to enable this
- Loading branch information
Luke Sikina
committed
Nov 16, 2023
1 parent
c4b6c19
commit 27f1242
Showing
3 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
106 changes: 106 additions & 0 deletions
106
initial-configuration/jenkins/jenkins-docker/jobs/Build and Deploy Microservice/config.xml
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,106 @@ | ||
<?xml version='1.1' encoding='UTF-8'?> | ||
<project> | ||
<actions/> | ||
<description>Build and deploy a microservice. The microservice must live in a directory in | ||
https://github.com/hms-dbmi/pic-sure-services/ | ||
</description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties> | ||
<hudson.model.ParametersDefinitionProperty> | ||
<parameterDefinitions> | ||
<hudson.model.StringParameterDefinition> | ||
<name>git_hash</name> | ||
<defaultValue>*/main</defaultValue> | ||
<trim>false</trim> | ||
</hudson.model.StringParameterDefinition> | ||
<hudson.model.StringParameterDefinition> | ||
<name>service_name</name> | ||
<description>The name of the directory for your service in the pic-sure-services repo</description> | ||
<trim>false</trim> | ||
</hudson.model.StringParameterDefinition> | ||
<hudson.model.StringParameterDefinition> | ||
<name>service_description</name> | ||
<description>Describe it</description> | ||
<trim>false</trim> | ||
</hudson.model.StringParameterDefinition> | ||
<hudson.model.FileParameterDefinition> | ||
<name>.env</name> | ||
<description>The .env file needed to run this service. The UUID will be added to the end of this env</description> | ||
</hudson.model.FileParameterDefinition> | ||
</parameterDefinitions> | ||
</hudson.model.ParametersDefinitionProperty> | ||
</properties> | ||
<scm class="hudson.plugins.git.GitSCM" plugin="git@5.2.1"> | ||
<configVersion>2</configVersion> | ||
<userRemoteConfigs> | ||
<hudson.plugins.git.UserRemoteConfig> | ||
<url>https://github.com/hms-dbmi/pic-sure-services.git</url> | ||
</hudson.plugins.git.UserRemoteConfig> | ||
</userRemoteConfigs> | ||
<branches> | ||
<hudson.plugins.git.BranchSpec> | ||
<name>${git_hash}</name> | ||
</hudson.plugins.git.BranchSpec> | ||
</branches> | ||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> | ||
<submoduleCfg class="empty-list"/> | ||
<extensions/> | ||
</scm> | ||
<canRoam>true</canRoam> | ||
<disabled>false</disabled> | ||
<blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> | ||
<blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> | ||
<triggers/> | ||
<concurrentBuild>false</concurrentBuild> | ||
<builders> | ||
<hudson.tasks.Shell> | ||
<command># Get the resource from the db if it exists | ||
export SQL="SELECT LOWER(CONCAT(SUBSTR(HEX(uuid), 1, 8), '-', SUBSTR(HEX(uuid), 9, 4), '-', SUBSTR(HEX(uuid), 13, 4), '-', SUBSTR(HEX(uuid), 17, 4), '-', SUBSTR(HEX(uuid), 21))) from picsure.resource where name = '$service_name'"; | ||
export resource_uuid=$(docker run -i -v /root/.my.cnf:/root/.my.cnf --network=host mysql mysql -se "$SQL" picsure); | ||
|
||
# Add the resource to the database if it doesn't already exist | ||
if [ -z "$resource_uuid" ]; then | ||
echo 'This is the first time building this resource. Adding to db' | ||
echo '' | ||
export SQL="INSERT IGNORE INTO picsure.resource (uuid, name, resourceRSPath, description) \ | ||
VALUES (UUID(), '$service_name', 'http://$service_name/', '$service_description')"; | ||
docker run -i -v /root/.my.cnf:/root/.my.cnf --network=host mysql mysql -e "$SQL" picsure | ||
fi | ||
|
||
# Get the resource from the db | ||
export SQL="SELECT LOWER(CONCAT(SUBSTR(HEX(uuid), 1, 8), '-', SUBSTR(HEX(uuid), 9, 4), '-', SUBSTR(HEX(uuid), 13, 4), '-', SUBSTR(HEX(uuid), 17, 4), '-', SUBSTR(HEX(uuid), 21))) from picsure.resource where name = '$service_name'"; | ||
export resource_uuid=$(docker run -i -v /root/.my.cnf:/root/.my.cnf --network=host mysql mysql -se "$SQL" picsure); | ||
echo '' | ||
echo "Done adding to db. Using $resource_uuid as uuid"; | ||
|
||
# Add the resource to our env file | ||
if grep -q 'RESOURCE_UUID' .env; then | ||
echo '' | ||
echo 'RESOURCE_UUID exists in .env. Replacing with our value' | ||
sed -i~ '/^RESOURCE_UUID=/s/=.*/="$resource_uuid"/' .env | ||
else | ||
echo '' | ||
echo 'RESOURCE_UUID does NOT exist in .env. Appending our to eof' | ||
echo RESOURCE_UUID=$resource_uuid >> .env | ||
fi | ||
|
||
|
||
# Copy over all the things | ||
echo '' | ||
echo 'Copying source code, partial compose file and .env' | ||
cp -r $service_name /pic-sure-services/ | ||
mv .env /pic-sure-services/$service_name/ | ||
cp docker-compose.yml /pic-sure-services/ | ||
cd /pic-sure-services/ | ||
|
||
# This find command just gets all the docker-compose files in this dir and the child dirs | ||
# All those files get merged together into one compose file | ||
echo '' | ||
echo 'Building and starting container. Good luck!' | ||
docker compose -f docker-compose.yml $(find ./* -maxdepth 2 -name '*docker-compose.yml' | sed -e 's/^/-f /' | xargs) up --build -d </command> | ||
<configuredLocalRules/> | ||
</hudson.tasks.Shell> | ||
</builders> | ||
<publishers/> | ||
<buildWrappers/> | ||
</project> |
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
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