Skip to content
Snippets Groups Projects
Verified Commit 6c2b25fc authored by Quentin Duchemin's avatar Quentin Duchemin
Browse files

Add a manual push on production registry and automatic test script

parent 7c3dcfb6
No related branches found
No related tags found
1 merge request!45Add a testing procedure
Pipeline #52559 failed
......@@ -141,8 +141,27 @@ docker-bench-security:
- master
- dev-ci
push-test:
stage: push
<<: *pull-modified-image
script:
- docker tag $REGISTRY_TEST/ci-builds/$MODIFIED_IMAGE:$CI_COMMIT_SHA $MODIFIED_IMAGE_FULL_TEST
- echo $REGISTRY_PASSWORD | docker login $REGISTRY -u $REGISTRY_USERNAME --password-stdin
# MODIFIED_IMAGE_FULL_TEST already should include the registry URL
- docker push $MODIFIED_IMAGE_FULL_TEST
after_script:
- docker logout $REGISTRY
only:
changes:
- "**/Dockerfile"
- "**/docker-compose.yml"
refs:
- master
- dev-ci
# Push the generated image on the production registry,
# once it passed all security tests and has been successfully built
# and run on the test virtual machine
push-prod:
stage: push
<<: *pull-modified-image
......@@ -160,3 +179,5 @@ push-prod:
refs:
- master
- dev-ci
when:
- manual
#!/bin/sh
function usage() {
echo -e "usage:\t$0 DIRECTORY, e.g. $0 pica-mattermost"
echo -e "\tDIRECTORY : name of the directory containing docker-compose.yml\n"
echo "This script simulates the first launch of a service : it will recreate all existing volumes for the service"
echo "to be sure that it works independently of the former configuration, and then launch 'docker-compose up -d'."
echo "This way, you can test your Dockerfile | docker-compose on the testing VM as if it was a brand new VM."
echo -e "\nAlso, it will temporarily replace all occurences of 'picasoft.net' by 'test.picasoft.net' for convenience."
echo -e "\nThis script will also use the image uploaded on the testing registry, not the production registry."
echo -e "\nUSE THIS SCRIPT ONLY ON THE TESTING VM."
exit 1
}
if [[ $(hostname) != *"test"* ]]; then
echo "ERROR : DO NOT USE OUTSIDE OF A TEST MACHINE !"
usage
fi
if [[ $# -ne 1 ]]; then
echo "ERROR : wrong number of arguments"
usage
fi
if [[ ! -d "$1" ]]; then
echo "ERROR : directory does not exist ($1)"
usage
fi
# Go to the folder of the service which will be tested
cd "$1"
echo -e "Starting procedure for $1...\n"
echo -e "\n==== Stop and remove existing containers ===="
docker-compose down
echo "==== Reset and pull Dockerfiles repository ===="
echo "Using branch" $(git branch --show-current)
git reset --hard
git pull
echo -e "\n==== Remove and re-create named external volumes ===="
for v in $(docker-compose config --volumes); do
docker volume rm "$v"
docker volume create "$v"
done
echo -e "\n==== Pull new versions of images ===="
docker-compose pull
echo -e "\n==== Replace production URL with testing URL in all files ===="
for f in $(grep -l -r ".picasoft.net" .); do
echo -e "\t*" ${f}
sed -i "s/.picasoft.net/.test.picasoft.net/g" ${f}
done
echo -e "\n==== Lauch $1 and restore repository ===="
docker-compose up -d
git reset --hard
echo -e "\n==== Print logs (use Ctrl+C to stop) ===="
docker-compose logs -f
......@@ -17,6 +17,8 @@ done
echo "export MODIFIED_IMAGE=${RES}" > variables
# Image name with wanted registry and tag, fetched from Docker Compose
RES=$(cat $RES/docker-compose.yml | grep $RES | cut -d ':' -f2- | tr -d ' ')
RES=$(cat $RES/docker-compose.yml | grep $RES | cut -d ':' -f2- | cut -d '/' -f2- | tr -d ' ')
if [ "$RES" = "" ]; then exit 1; fi
echo "export MODIFIED_IMAGE_FULL=${RES}" >> variables
echo "export MODIFIED_IMAGE_FULL_TEST=registry.test.picasoft.net/${RES}" >> variables
echo "export MODIFIED_IMAGE_FULL=registry.picasoft.net/${RES}" >> variables
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment