Skip to content

Commit

Permalink
#534 Fill the CI's docker-up pipe with data (#536)
Browse files Browse the repository at this point in the history
* Create wait-for.sh. Fill the db for docker-up pipeline.

* Add copyright notice to wait-for
  • Loading branch information
ArtemijRodionov committed Sep 23, 2018
1 parent 8ed1f8b commit b15dcf0
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 82 deletions.
22 changes: 11 additions & 11 deletions .drone.yml
Expand Up @@ -121,16 +121,18 @@ pipeline:
commands:
- cd docker
- cp drone_env/* env_files/
- cp drone_env/.env .
- for x in drone_env/*; do cat $x >> .env; done;
- docker-compose up -d app-drone
- docker-compose logs app-drone
# @todo #517:60m Fill drone-sided app with data.
# Do migrate and fixtures load.
# Currently we faced with issues here:
# https://ci.fidals.com/fidals/shopelectro/721/3
# Then try to resurrect health check.
- docker-compose exec -T app-drone docker/wait-for.sh postgres:5432 -- python manage.py migrate
- docker-compose exec -T app-drone python manage.py custom_pages
# - docker-compose exec -T app-drone docker/wait-for.sh localhost:8000 -- docker/check-health.sh localhost:8000

# @todo #534:60m Fix CI's error for docker-up pipe.
# Any of below commands returns this: "/bin/sh: syntax error: unterminated quoted string"
# docker-compose exec -T app-drone nc -z google.com 80 > /dev/null 2>&1
# docker-compose exec -T app-drone wget google.com
# docker-compose exec -T app-drone docker/check-health.sh localhost:8000

# - docker-compose exec -T app-drone bash -c "./docker/check-health.sh http://0.0.0.0:8000/"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
when:
Expand All @@ -140,9 +142,7 @@ pipeline:
image: docker/compose:1.22.0
commands:
- cd docker
- cp drone_env/* env_files/
- cp drone_env/.env .
- docker-compose logs app
- docker-compose logs app-drone
- docker-compose rm -fs
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Expand Down
11 changes: 7 additions & 4 deletions docker/check-health.sh
@@ -1,8 +1,11 @@
#!/usr/bin/env bash

set -e
#!/usr/bin/env sh

URL=$1
[[ $URL ]] || (echo "Specify an url to be checked as the first argument" && exit 1)

if [ -z $URL ]
then
echo "Specify an url to be checked as the first argument"
exit 1
fi

wget -O- $URL -q | grep shopelectro.ru > /dev/null && echo "OK" || exit 1
2 changes: 1 addition & 1 deletion docker/docker-compose-production.yml
Expand Up @@ -30,7 +30,7 @@ services:
networks:
- se-backend
- se-frontend
command: gunicorn shopelectro.wsgi:application -c /etc/gunicorn.py -b 0.0.0.0:$VIRTUAL_HOST_PORT
command: ./docker/wait-for.sh postgres:5432 -- gunicorn shopelectro.wsgi:application -c /etc/gunicorn.py -b 0.0.0.0:$VIRTUAL_HOST_PORT

celery-beat:
image: fidals/se:prod
Expand Down
6 changes: 1 addition & 5 deletions docker/docker-compose.yml
Expand Up @@ -18,8 +18,7 @@ services:
- $VIRTUAL_HOST_LIVESERVER_PORT
networks:
- se-backend
- se-frontend
command: python manage.py runserver 0.0.0.0:$VIRTUAL_HOST_PORT
command: ./docker/wait-for.sh postgres:5432 -- python manage.py runserver 0.0.0.0:$VIRTUAL_HOST_PORT

app-drone:
extends: app-base
Expand Down Expand Up @@ -66,8 +65,6 @@ services:
- env_files/credentials
networks:
- se-backend
volumes:
- $POSTGRES_DATA_DIR:/var/lib/postgresql/data

rabbitmq:
image: rabbitmq:management-alpine
Expand Down Expand Up @@ -142,4 +139,3 @@ services:

networks:
se-backend:
se-frontend:
57 changes: 0 additions & 57 deletions docker/drone_env/.env

This file was deleted.

2 changes: 1 addition & 1 deletion docker/drone_env/app
Expand Up @@ -5,7 +5,7 @@ COMPOSE_PROJECT_NAME=drone_shopelectro
ENV_TYPE=LOCAL

# App related settings
DJANGO_SETTINGS_MODULE=shopelectro.settings.local
DJANGO_SETTINGS_MODULE=shopelectro.settings.drone
DJANGO_LOG_LEVEL=INFO
SECRET_KEY=secret-key
STAGE_SECRET_KEY=another-secret-key
Expand Down
5 changes: 2 additions & 3 deletions docker/images/python/Dockerfile.dev
Expand Up @@ -2,9 +2,8 @@ FROM python:3.7-slim

RUN apt-get update \
# wget is needed for working with ftp
# git is needed for pip
&& apt-get install --no-install-recommends --no-install-suggests -y wget git make \
&& apt-get remove --purge -y git \
# netcat is needed for waiting of postgres at `dc up -d app`
&& apt-get install --no-install-recommends --no-install-suggests -y wget netcat \
&& apt-get -y --purge autoremove \
&& rm -rf /var/lib/apt/lists/*

Expand Down
92 changes: 92 additions & 0 deletions docker/wait-for.sh
@@ -0,0 +1,92 @@
#!/usr/bin/env sh

# The MIT License (MIT)
# Copyright (c) 2016 Giles Hall

# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

TIMEOUT=15
QUIET=0

echoerr() {
if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
}

usage() {
exitcode="$1"
cat << USAGE >&2
Usage:
$cmdname host:port [-t timeout] [-- command args]
-q | --quiet Do not output any status messages
-t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
-- COMMAND ARGS Execute command with args after the test finishes
USAGE
exit "$exitcode"
}

wait_for() {
for i in `seq $TIMEOUT` ; do
nc -z "$HOST" "$PORT" > /dev/null 2>&1

result=$?
if [ $result -eq 0 ] ; then
if [ $# -gt 0 ] ; then
exec "$@"
fi
exit 0
fi
sleep 1
done
echo "Operation timed out" >&2
exit 1
}

while [ $# -gt 0 ]
do
case "$1" in
*:* )
HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
shift 1
;;
-q | --quiet)
QUIET=1
shift 1
;;
-t)
TIMEOUT="$2"
if [ "$TIMEOUT" = "" ]; then break; fi
shift 2
;;
--timeout=*)
TIMEOUT="${1#*=}"
shift 1
;;
--)
shift
break
;;
--help)
usage 0
;;
*)
echoerr "Unknown argument: $1"
usage 1
;;
esac
done

if [ "$HOST" = "" -o "$PORT" = "" ]; then
echoerr "Error: you need to provide a host and port to test."
usage 2
fi

wait_for "$@"

2 comments on commit b15dcf0

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on b15dcf0 Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 517-a10609a6 disappeared from .drone.yml, that's why I closed #534. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on b15dcf0 Sep 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 534-ecbd61f7 discovered in .drone.yml and submitted as #587. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.