-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace Vagrant with Docker Compose for running functional tests (#539)
* Replace Vagrant with Docker Compose * Reenable functional tests in CI * Stream docker compose output while building image * Fix RuboCop issue and Ruby 2 compat * Wait for Docker container to start, to avoid test flake
- Loading branch information
1 parent
830751c
commit c8401f8
Showing
18 changed files
with
151 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
FROM ubuntu:22.04 | ||
WORKDIR /provision | ||
COPY ./ubuntu_setup.sh ./ | ||
RUN ./ubuntu_setup.sh | ||
EXPOSE 22 | ||
CMD ["/usr/sbin/sshd", "-D"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
apt -y update | ||
|
||
# Create `deployer` user that can sudo without a password | ||
apt-get -y install sudo | ||
adduser --disabled-password deployer < /dev/null | ||
echo "deployer:topsecret" | chpasswd | ||
echo "deployer ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers | ||
|
||
# Install and configure sshd | ||
apt-get -y install openssh-server | ||
{ | ||
echo "Port 22" | ||
echo "PasswordAuthentication yes" | ||
echo "ChallengeResponseAuthentication no" | ||
} >> /etc/ssh/sshd_config | ||
mkdir /var/run/sshd | ||
chmod 0755 /var/run/sshd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ | |
bin/rake | ||
.bundle | ||
.yardoc | ||
.vagrant* | ||
test/tmp | ||
Gemfile.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
name: sshkit | ||
|
||
services: | ||
ssh_server: | ||
build: | ||
context: .docker | ||
ports: | ||
- "2122:22" |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def setup | |
end | ||
|
||
def a_host | ||
VagrantWrapper.hosts['one'] | ||
DockerWrapper.host | ||
end | ||
|
||
def test_simple_netssh | ||
|
24 changes: 0 additions & 24 deletions
24
test/functional/test_ssh_server_comes_up_for_functional_tests.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
require "socket" | ||
|
||
Minitest.after_run do | ||
DockerWrapper.stop if DockerWrapper.running? | ||
end | ||
|
||
module DockerWrapper | ||
SSH_SERVER_PORT = 2122 | ||
|
||
class << self | ||
def host | ||
SSHKit::Host.new( | ||
user: "deployer", | ||
hostname: "localhost", | ||
port: SSH_SERVER_PORT, | ||
password: "topsecret", | ||
ssh_options: host_verify_options | ||
) | ||
end | ||
|
||
def running? | ||
out, status = run_compose_command("ps --status running", false) | ||
status.success? && out.include?("ssh_server") | ||
end | ||
|
||
def start | ||
run_compose_command("up -d") | ||
end | ||
|
||
def stop | ||
run_compose_command("down") | ||
end | ||
|
||
def wait_for_ssh_server(retries=3) | ||
Socket.tcp("localhost", SSH_SERVER_PORT, connect_timeout: 1).close | ||
sleep(1) | ||
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT | ||
retries -= 1 | ||
sleep(2) && retry if retries.positive? | ||
raise | ||
end | ||
|
||
private | ||
|
||
def run_compose_command(command, echo=true) | ||
$stderr.puts "[docker compose] #{command}" if echo | ||
Open3.popen2e("docker compose #{command}") do |stdin, outerr, wait_thread| | ||
stdin.close | ||
output = Thread.new { capture_stream(outerr, echo) } | ||
[output.value, wait_thread.value] | ||
end | ||
end | ||
|
||
def capture_stream(stream, echo=true) | ||
buffer = String.new | ||
while (line = stream.gets) | ||
buffer << line | ||
$stderr.puts("[docker compose] #{line}") if echo | ||
end | ||
buffer | ||
end | ||
|
||
def host_verify_options | ||
if Net::SSH::Version::MAJOR >= 5 | ||
{ verify_host_key: :never } | ||
else | ||
{ paranoid: false } | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.