Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎉 Integration Testing for SSH using a docker container | Postgres Source and Destination update integration tests using ssh bastion in docker container #6312

Conversation

VitaliiMaltsev
Copy link
Contributor

@VitaliiMaltsev VitaliiMaltsev commented Sep 20, 2021

What

Improve the process of acceptance testing by allowing doing acceptance / integration testing using a bastion running in a docker container. Right now we have a dedicated host in AWS that we use.

Why do we care?

  1. We'd rather not maintain the bastion infra if we don't have to

  2. It means that the tests require secrets as an input which adds a bit more friction. If we use docker that would not be necessary.

  3. It requires having a static instance of the database we trying to test running! Because the bastion is static it also needs to be forwarding to some database in our VPC so we need a statically running db as well. This limits the tests we can right and means we're paying for and maintaining a database for no good reason. Ideally we could spin up dbs and bastion all in docker!

How

A new SshBastion class has been implemented, which allows you to initialize and run a bastion ssh server created in a docker test container. The test database and bastion run in containers on the same network. Connection configuration for integration tests is now taken directly from container settings and does not require a real database connection. Establishing an ssh tunnel implies 2 authentication options - using a password or using a private key

Recommended reading order

  1. x.java
  2. y.python

Pre-merge Checklist

Expand the relevant checklist and delete the others.

New Connector

Community member or Airbyter

  • Community member? Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • docs/SUMMARY.md
    • docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
    • docs/integrations/README.md
    • airbyte-integrations/builds.md
  • PR name follows PR naming conventions
  • Connector added to connector index like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Updating a connector

Community member or Airbyter

  • Grant edit access to maintainers (instructions)
  • Secrets in the connector's spec are annotated with airbyte_secret
  • Unit & integration tests added and passing. Community members, please provide proof of success locally e.g: screenshot or copy-paste unit, integration, and acceptance test output. To run acceptance tests for a Python connector, follow instructions in the README. For java connectors run ./gradlew :airbyte-integrations:connectors:<name>:integrationTest.
  • Code reviews completed
  • Documentation updated
    • Connector's README.md
    • Connector's bootstrap.md. See description and examples
    • Changelog updated in docs/integrations/<source or destination>/<name>.md including changelog. See changelog example
  • PR name follows PR naming conventions
  • Connector version bumped like described here

Airbyter

If this is a community PR, the Airbyte engineer reviewing this PR is responsible for the below items.

  • Create a non-forked branch based on this PR and test the below items on it
  • Build is successful
  • Credentials added to Github CI. Instructions.
  • /test connector=connectors/<name> command is passing.
  • New Connector version released on Dockerhub by running the /publish command described here

Connector Generator

  • Issue acceptance criteria met
  • PR name follows PR naming conventions
  • If adding a new generator, add it to the list of scaffold modules being tested
  • The generator test modules (all connectors with -scaffold in their name) have been updated with the latest scaffold by running ./gradlew :airbyte-integrations:connector-templates:generator:testScaffoldTemplates then checking in your changes
  • Documentation which references the generator is updated as needed.

@github-actions github-actions bot added the area/connectors Connector related issues label Sep 20, 2021
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 20, 2021 11:43 Inactive
@VitaliiMaltsev VitaliiMaltsev changed the title Vmaltsev/5811ssh tunnel integration testing in docker containers 🎉 Integration Testing for SSH using a docker container Sep 20, 2021
@github-actions github-actions bot added the area/documentation Improvements or additions to documentation label Sep 20, 2021
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 20, 2021 13:17 Inactive
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 20, 2021 13:47 Inactive
@VitaliiMaltsev VitaliiMaltsev changed the title 🎉 Integration Testing for SSH using a docker container 🎉 Integration Testing for SSH using a docker container | Postgres Source and Destination update integration tests using ssh bastion in docker container Sep 20, 2021
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 20, 2021 14:23 Inactive
@VitaliiMaltsev VitaliiMaltsev linked an issue Sep 20, 2021 that may be closed by this pull request
Copy link
Contributor

@alexandr-shegeda alexandr-shegeda left a comment

Choose a reason for hiding this comment

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

LGTM

@DoNotPanicUA
Copy link
Contributor

I would only recommend not to increase the version at files airbyte-config/init/src/main/resources/seed/destination_definitions.yaml like that before you get external approval. If you increase the version before pulling the image, builds, and tests fail.

@VitaliiMaltsev VitaliiMaltsev marked this pull request as ready for review September 22, 2021 09:19
Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Looks great! a few comments:

  1. Is there a reason we can't treat the bastion as a normal object the same way other test containers are? Right now it's static/global which could introduce isolation issues
  2. could you remove the places where we inject secrets in ci_credentials.sh for the current postgres ssh test case and once you merge this pr remove them from environment secrets as well in github?
  3. you actually don't need to bump the postgres container versions since this is just changing their tests not the connector itself

@@ -263,14 +263,21 @@ Using this feature requires additional configuration, when creating the source.
6. If you are using `Password Authentication`, then `SSH Login Username` should be set to the password of the User from the previous step. If you are using `SSH Key Authentication` leave this blank. Again, this is not the Postgres password, but the password for the OS-user that Airbyte is using to perform commands on the bastion.
7. If you are using `SSH Key Authentication`, then `SSH Private Key` should be set to the RSA Private Key that you are using to create the SSH connection. This should be the full contents of the key file starting with `-----BEGIN RSA PRIVATE KEY-----` and ending with `-----END RSA PRIVATE KEY-----`.


## Integration tests to Postgres via an SSH Tunnel with bastion in docker container
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go in the README for the connector rather than this doc. This doc is meant for consumption by Airbyte users, and this is an implementation detail of how we test the connector

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should go in the README for the connector rather than this doc. This doc is meant for consumption by Airbyte users, and this is an implementation detail of how we test the connector

removed description from this doc

private static final String SSH_USER = "sshuser";
private static final String SSH_PASSWORD = "secret";
private static Network network;
private static GenericContainer bastion;
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this all static instead of instance variables?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why is this all static instead of instance variables?

replaced with instance variables

import org.testcontainers.containers.Network;
import org.testcontainers.images.builder.ImageFromDockerfile;

public class SshBastion {
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest adding the word Container to the. name e.g: SshBastionContainer to make it clear it's containerized

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest adding the word Container to the. name e.g: SshBastionContainer to make it clear it's containerized

good point! Renamed class to SshBastionContainer

@@ -24,45 +24,79 @@

package io.airbyte.integrations.io.airbyte.integration_tests.sources;

import static io.airbyte.integrations.base.ssh.SshBastion.*;
Copy link
Contributor

Choose a reason for hiding this comment

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

style: prefer using explicit import instead of star imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

style: prefer using explicit import instead of star imports

replaced star import with explicit

…stionContainer, removed ci credentials for ssh Postgres Source and Destination
@github-actions github-actions bot removed the area/documentation Improvements or additions to documentation label Sep 23, 2021
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 23, 2021 19:36 Inactive
@VitaliiMaltsev
Copy link
Contributor Author

Looks great! a few comments:

  1. Is there a reason we can't treat the bastion as a normal object the same way other test containers are? Right now it's static/global which could introduce isolation issues
  2. could you remove the places where we inject secrets in ci_credentials.sh for the current postgres ssh test case and once you merge this pr remove them from environment secrets as well in github?
  3. you actually don't need to bump the postgres container versions since this is just changing their tests not the connector itself
  1. Yes, you are right. Replaced static initialization with initialization of the new instance of class
  2. Done
  3. Revert changes with version bumping

…g-in-docker-containers

# Conflicts:
#	tools/bin/ci_credentials.sh
@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 23, 2021 19:55 Inactive
Copy link
Contributor

@sherifnada sherifnada left a comment

Choose a reason for hiding this comment

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

Great work!

@VitaliiMaltsev VitaliiMaltsev temporarily deployed to more-secrets September 24, 2021 06:53 Inactive
@VitaliiMaltsev VitaliiMaltsev merged commit ec3951b into master Sep 24, 2021
@VitaliiMaltsev VitaliiMaltsev deleted the vmaltsev/5811ssh-tunnel-integration-testing-in-docker-containers branch September 24, 2021 17:00
@cgardens
Copy link
Contributor

cgardens commented Sep 27, 2021

@VitaliiMaltsev this is awesome! it will make developing new ssh connectors much easier. great work.

Comment on lines +54 to +59
### Acceptance Testing via ssh tunnel using SshBastion and JdbcDatabaseContainer in Docker
1. The `SshBastion` class provides 3 helper functions:
`initAndStartBastion()`to initialize and start SSH Bastion server in Docker test container and creates new `Network` for bastion and tested jdbc container
`getTunnelConfig()`which return JsoneNode with all necessary configuration to establish ssh tunnel. Connection configuration for integration tests is now taken directly from container settings and does not require a real database connection
`stopAndCloseContainers` to stop and close SshBastion and JdbcDatabaseContainer at the end of the test

Copy link
Contributor

@ChristopheDuong ChristopheDuong Feb 28, 2022

Choose a reason for hiding this comment

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

  • Does this mean we can update the Future Work section of this readme.md file and remove the bullet point?

Improve the process of acceptance testing by allowing doing acceptance testing using a bastion running in a docker container instead of having to use dedicated infrastructure and a static database.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/connectors Connector related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Integration Testing for SSH using a docker container
6 participants