Add dockerised tests

This commit is contained in:
Derry Hamilton 2019-06-17 12:53:31 +01:00
parent 3badb97d49
commit 5571bd1b4d
14 changed files with 143 additions and 76 deletions

View file

@ -1,4 +1,2 @@
#!/bin/bash
set -e
cp *.rpm docker/run/
docker build --rm -t local/c7-runhost docker/run
docker build --target deploy -t rasilon/ujetl docker/multistage

5
build_util/run_docker_tests Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
docker-compose -f docker/test_compose/docker-compose.yml run --rm tests
docker-compose -f docker/test_compose/docker-compose.yml down

View file

@ -1,31 +0,0 @@
# General build RPM environment for CentOS 6.x
#
# VERSION 0.0.1
FROM centos:centos7
MAINTAINER Derry Hamilton <derryh@rasilon.net>
# Install up-to-date epel rpm repository
RUN yum -y install epel-release
# Install java first, to get a sensible one.
RUN yum -y install java-1.8.0-openjdk-devel
# Install various packages to get compile environment
RUN yum -y groupinstall 'Development Tools'
# Install git command to access GitHub repository
RUN yum -y install git
# Install rpm-build to use rpmrebuild command
RUN yum -y install rpm-build
# Install yum-utils to use yumdownloader command
RUN yum -y install yum-utils
# Install rpmdevtools to use rpmdev-setuptree command
RUN yum -y install rpmdevtools
# Install rpmdevtools to use rpmdev-setuptree command
RUN yum -y install maven
RUN mkdir -p /root/rpmbuild/SOURCES

View file

@ -8,17 +8,24 @@ RUN cd ujetl && mvn package
#FROM centos:centos7
FROM openjdk:8-alpine
MAINTAINER Derry Hamilton <derryh@rasilon.net>
FROM openjdk:8-alpine as runner
LABEL maintainer="Derry Hamilton <derryh@rasilon.net>"
#RUN yum -y install epel-release
#RUN yum -y install java-1.8.0-openjdk-devel
RUN apk update && apk upgrade && apk add bash
RUN mkdir -p /usr/share/ujetl/lib/ /var/ujetl /etc/ujetl
COPY --from=builder /ujetl/target/CopyingApp-2.*-jar-with-dependencies.jar /usr/share/ujetl/lib/CopyingApp.jar
COPY --from=builder /ujetl/install_extra/copying_defaults_log4j.xml /etc/ujetl/
COPY docker/multistage/ujetl_entrypoint /
ENTRYPOINT ["/ujetl_entrypoint"]
COPY ujetl_entrypoint /
CMD ["/ujetl_entrypoint"]
FROM runner as tester
COPY TEST_config_live.xml /var/ujetl/
COPY wait_for_postgres /
RUN apk add postgresql-client
FROM runner as deploy
# Convice docker cloud to build the deploy image

View file

@ -0,0 +1,52 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<CopyingApp>
<hardLimitSeconds>360000</hardLimitSeconds>
<nRowsToLog>10000</nRowsToLog>
<blockSize>1000</blockSize>
<source>
<dsn>jdbc:postgresql://testdb:5432/test</dsn>
<username>test</username>
<password>test</password>
<networkTimeout>600000</networkTimeout>
</source>
<dest>
<dsn>jdbc:postgresql://testdb:5432/test</dsn>
<username>test</username>
<password>test</password>
</dest>
<jobs>
<job>
<name>test</name>
<key>select coalesce(-1,max(id),-1) as key from dest</key>
<select>
select
id,
test_int,
test_text,
test_ts
from
public.source where id > ?::bigint</select>
<insert>
insert into public.dest(
id,
test_int,
test_text,
test_ts
)values(
?::bigint,
?::integer,
?::text,
?::timestamp with time zone
)ON CONFLICT(id) DO UPDATE
set
test_int = EXCLUDED.test_int,
test_text = EXCLUDED.test_text,
test_ts = EXCLUDED.test_ts
WHERE
dest.test_int = EXCLUDED.test_int
OR dest.test_text = EXCLUDED.test_text
OR dest.test_ts = EXCLUDED.test_ts
</insert>
</job>
</jobs>
</CopyingApp>

View file

@ -4,6 +4,10 @@ set -e
LOG_PROPS=/etc/ujetl/copying_defaults_log4j.xml
cd /var/ujetl
echo Currently in `pwd`
echo processing files:
ls
echo Starting run loop
for file in *.xml
do
/usr/bin/java \

View file

@ -0,0 +1,12 @@
#!/bin/bash
set -e
cmd="$@"
until PGPASSWORD=test psql -h "testdb" -U "test" -c 'SELECT 1 FROM public.container_ready' postgres; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $cmd

View file

@ -1,18 +0,0 @@
# General build RPM environment for CentOS 6.x
#
# VERSION 0.0.1
FROM centos:centos7
MAINTAINER Derry Hamilton <derryh@rasilon.net>
# Install up-to-date epel rpm repository
RUN yum -y install epel-release
# Install java first, to get a sensible one.
RUN yum -y install java-1.8.0-openjdk-devel
COPY uJETL-2.*.x86_64.rpm /tmp/
COPY ujetl_entrypoint /
RUN rpm -i /tmp/uJETL-2.*.x86_64.rpm
ENTRYPOINT ["/ujetl_entrypoint"]

View file

@ -1,17 +0,0 @@
#!/bin/bash
set -e
LOG_PROPS=/etc/ujetl/copying_defaults_log4j.xml
cd /var/ujetl
for file in *.xml
do
/usr/bin/java \
-Xms1g \
-Xmx2g \
-cp /usr/share/ujetl/lib/CopyingApp.jar \
com.rasilon.ujetl.CopyingApp \
--log4j "$LOG_PROPS" \
--config "$file"
done

View file

@ -0,0 +1,23 @@
# This is a sample to help put the full application together
version: '3.3'
services:
testdb:
image: rasilon/ujetl_testdb:latest
build:
context: ../test_db
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
tests:
image: rasilon/ujetl_test:latest
build:
context: ../multistage
links:
- "testdb"
command: ["/wait_for_postgres", "/ujetl_entrypoint"]

View file

@ -0,0 +1,3 @@
FROM postgres:11
COPY setup.sql /docker-entrypoint-initdb.d/
COPY is_ready /

3
docker/test_db/is_ready Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
/usr/lib/postgresql/9.6/bin/psql -U postgres -c "SELECT 1 FROM public.container_ready" postgres

26
docker/test_db/setup.sql Normal file
View file

@ -0,0 +1,26 @@
CREATE DATABASE test;
\c test
CREATE ROLE test login password 'test';
CREATE UNLOGGED TABLE source (
id bigserial primary key,
test_int integer,
test_text text,
test_ts timestamp with time zone
);
CREATE UNLOGGED TABLE dest (
id bigint primary key,
test_int integer,
test_text text,
test_ts timestamp with time zone
);
GRANT SELECT ON source to test;
GRANT SELECT,INSERT,UPDATE,DELETE ON dest TO test;
INSERT INTO source(test_int,test_text,test_ts) SELECT 1,'banana',now() FROM generate_series(1,100000);
\c postgres
CREATE TABLE public.container_ready AS SELECT 1 FROM(VALUES(1)) AS a(a);
GRANT SELECT ON public.container_ready TO TEST;