Skip to content

Commit

Permalink
Removed MySql dep. Added ability to specify custom registry
Browse files Browse the repository at this point in the history
  • Loading branch information
shanejansen committed Jan 9, 2024
1 parent d48c652 commit cd31310
Show file tree
Hide file tree
Showing 30 changed files with 57 additions and 462 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ Your services and their monitored dependencies are defined here. Default values
* View each [dependency's docs](#dependencies) for values and additional configuration.

### `/defaults`
[Example](./examples/java-spring/touchstone/defaults/mysql.yml)
This directory contains YAML files where default values for dependencies are defined. Defaults make it easy to test your service(s) locally by setting up your dependencies with sensible defaults. The name of each YAML file should match the name of a dependency. For instance, with the MySQL dependency, a `mysql.yml` file would contain default databases and tables to be created as well as statements to insert initial data. View each [dependency's docs](#dependencies) for allowable values.
[Example](./examples/java-spring/touchstone/defaults/postgres.yml)
This directory contains YAML files where default values for dependencies are defined. Defaults make it easy to test your service(s) locally by setting up your dependencies with sensible defaults. The name of each YAML file should match the name of a dependency. For instance, with the Postgres dependency, a `postgres.yml` file would contain default databases and tables to be created as well as statements to insert initial data. View each [dependency's docs](#dependencies) for allowable values.


### `/tests`
Expand Down Expand Up @@ -108,7 +108,7 @@ example, foo-app might make a call to `bar-app:8080/some-endpoint`.

* [HTTP](./docs/dependencies/http.md)
* [Mongo DB](./docs/dependencies/mongodb.md)
* [MySQL](./docs/dependencies/mysql.md)
* [Postgres](./docs/dependencies/postgres.md)
* [Rabbit MQ](./docs/dependencies/rabbitmq.md)
* [S3](./docs/dependencies/s3.md)
* [Filesystem](./docs/dependencies/filesystem.md)
Expand Down
37 changes: 0 additions & 37 deletions docs/dependencies/mysql.md

This file was deleted.

6 changes: 3 additions & 3 deletions examples/java-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.7.1</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.datasource.url=jdbc:mysql://${TS_MYSQL_HOST}:${TS_MYSQL_PORT}/myapp
spring.datasource.url=jdbc:postgresql://${TS_POSTGRES_HOST}:${TS_POSTGRSE_PORT}/myapp
app.email-service=${TS_HTTP_URL}
spring.rabbitmq.host=${TS_RABBITMQ_HOST}
spring.rabbitmq.port=${TS_RABBITMQ_PORT}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spring.datasource.url=jdbc:mysql://localhost:3306/myapp
spring.datasource.url=jdbc:postgresql://localhost:3306/myapp
spring.datasource.username=root
spring.datasource.password=root
app.email-service=http://localhost:9090
Expand Down
4 changes: 2 additions & 2 deletions examples/java-spring/touchstone/tests/creds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MYSQL_DATABASE = 'myapp'
MYSQL_TABLE = 'users'
POSTGRES_DATABASE = 'myapp'
POSTGRES_TABLE = 'users'
MONGO_DATABASE = 'myapp'
MONGO_COLLECTION = 'orders'
14 changes: 7 additions & 7 deletions examples/java-spring/touchstone/tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def given(self) -> object:
'lastName': 'Brown',
'email': '[email protected]'
}
self.deps.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given)
self.deps.postgres.setup().insert_row(creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, given)
return given

def when(self, given) -> object:
Expand Down Expand Up @@ -60,8 +60,8 @@ def then(self, given, result) -> bool:
'lastName': given['lastName'],
'email': given['email']
}
return validation.matches(expected_response, result) and self.deps.mysql.verify().row_exists(
creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given)
return validation.matches(expected_response, result) and self.deps.postgres.verify().row_exists(
creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, given)


class PutUser(TouchstoneTest):
Expand All @@ -85,15 +85,15 @@ def given(self) -> object:
'lastName': 'Brown',
'email': '[email protected]'
}
self.deps.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, existing_user)
self.deps.postgres.setup().insert_row(creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, existing_user)
return new_info

def when(self, given) -> object:
http.put_json(f'{self.service_url}/user', given)
return None

def then(self, given, result) -> bool:
return self.deps.mysql.verify().row_exists(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, given)
return self.deps.postgres.verify().row_exists(creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, given)


class DeleteUser(TouchstoneTest):
Expand All @@ -117,7 +117,7 @@ def given(self) -> object:
'lastName': 'Brown',
'email': '[email protected]'
}
self.deps.mysql.setup().insert_row(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, user)
self.deps.postgres.setup().insert_row(creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, user)
return user_id

def when(self, given) -> object:
Expand All @@ -129,4 +129,4 @@ def then(self, given, result) -> bool:
'id': given
}
return self.deps.rabbitmq.verify().payload_published('user.exchange', str(given), 'user-deleted') and \
self.deps.mysql.verify().row_does_not_exist(creds.MYSQL_DATABASE, creds.MYSQL_TABLE, where)
self.deps.postgres.verify().row_does_not_exist(creds.POSTGRES_DATABASE, creds.POSTGRES_TABLE, where)
2 changes: 1 addition & 1 deletion examples/java-spring/touchstone/touchstone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dependencies:
rabbitmq:
auto_create: False
mongodb:
mysql:
postgres:
2 changes: 1 addition & 1 deletion examples/python-spark/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY ./jars ./jars
COPY ./src ./src
CMD spark-submit --jars jars/mysql-connector-java-8.0.21.jar ./src/main.py
CMD spark-submit --jars jars/postgresql-42.7.1.jar ./src/main.py
Binary file not shown.
8 changes: 4 additions & 4 deletions examples/python-spark/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class Config(object):
def __init__(self):
self.vars = {
'db_host': os.getenv('TS_MYSQL_HOST', 'localhost'),
'db_port': os.getenv('TS_MYSQL_PORT', '3306'),
'db_username': os.getenv('TS_MYSQL_USERNAME', 'root'),
'db_password': os.getenv('TS_MYSQL_PASSWORD', 'root')
'db_host': os.getenv('TS_POSTGRES_HOST', 'localhost'),
'db_port': os.getenv('TS_POSTGRES_PORT', '3306'),
'db_username': os.getenv('TS_POSTGRES_USERNAME', 'root'),
'db_password': os.getenv('TS_POSTGRES_PASSWORD', 'root')
}
4 changes: 2 additions & 2 deletions examples/python-spark/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

emails = spark.read.csv('./touchstone/io/emails.csv').toDF('name', 'email')
numbers = spark.read.format('jdbc').options(
url=f'jdbc:mysql://{config.vars["db_host"]}:{config.vars["db_port"]}/myapp',
driver='com.mysql.jdbc.Driver',
url=f'jdbc:postgresql://{config.vars["db_host"]}:{config.vars["db_port"]}/myapp',
driver='com.postgresql.jdbc.Driver',
dbtable='numbers',
user=config.vars['db_username'],
password=config.vars['db_password']
Expand Down
2 changes: 1 addition & 1 deletion examples/python-spark/touchstone/tests/test_csv_matches.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def given(self) -> object:
writer.writerow(['name', 'email'])
writer.writerow(['John', '[email protected]'])
writer.writerow(['Jane', '[email protected]'])
self.deps.mysql.setup().insert_rows('myapp', 'numbers', [
self.deps.postgres.setup().insert_rows('myapp', 'numbers', [
{
'name': 'John',
'number': '5555551234'
Expand Down
4 changes: 2 additions & 2 deletions examples/python-spark/touchstone/touchstone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
- name: my-exec
type: executable
dockerfile: ../Dockerfile
develop_command: spark-submit --jars jars/mysql-connector-java-8.0.21.jar ./src/main.py
develop_command: spark-submit --jars jars/postgresql-42.7.1.jar ./src/main.py
dependencies:
filesystem:
mysql:
postgres:
17 changes: 8 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
author_email='[email protected]',
packages=find_packages(exclude=['tests']),
install_requires=[
'pyfiglet~=0.8',
'click~=7.0',
'pika~=1.1',
'pyyaml~=5.4',
'pymongo~=3.10',
'pymysql~=0.9.3',
'minio~=5.0.7',
'redis~=3.5.3',
'psycopg2-binary~=2.9.3'
'pyfiglet>=0.8',
'click>=8.1.7',
'pika>=1.3.2',
'pyyaml>=6.0.1',
'pymongo>=4.6.1',
'minio>=7.2.3',
'redis>=5.0.1',
'psycopg2-binary>=2.9.9'
],
entry_points={
'console_scripts': [
Expand Down
7 changes: 0 additions & 7 deletions touchstone-tests/touchstone/defaults/mysql.yml

This file was deleted.

87 changes: 0 additions & 87 deletions touchstone-tests/touchstone/tests/test_mysql.py

This file was deleted.

3 changes: 2 additions & 1 deletion touchstone-tests/touchstone/touchstone.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
---
touchstone_version: 1.4.2
docker:
registry: docker-all.artifactory.8451.cloud
services:
- name: my-app
port: 8080
Expand All @@ -13,7 +15,6 @@ dependencies:
http:
rabbitmq:
mongodb:
mysql:
postgres:
s3:
filesystem:
Expand Down
3 changes: 2 additions & 1 deletion touchstone/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def __init__(self, is_dev_mode=False, should_log_services=False):
log_directory = os.path.join(root, 'logs')
os.makedirs(log_directory, exist_ok=True)
self.ts_context = TsContext()
self.docker_manager = DockerManager(should_auto_discover=not is_dev_mode)
self.docker_manager = DockerManager(should_auto_discover=not is_dev_mode,
registry=touchstone_config.get_config()['docker']['registry'])
self.deps = self.__build_deps(is_dev_mode,
touchstone_config.get_config()['root'],
touchstone_config.get_config()['dependencies'])
Expand Down
3 changes: 3 additions & 0 deletions touchstone/lib/configurers/touchstone_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ class TouchstoneConfig(IConfigurable):
def __init__(self, root):
self.__basic_configurer = BasicConfigurer({
'root': root,
'docker': {
'registry': ''
},
'services': [],
'dependencies': []
})
Expand Down
Loading

0 comments on commit cd31310

Please sign in to comment.