-
Notifications
You must be signed in to change notification settings - Fork 255
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
Replace Vagrant with Docker Compose for running functional tests #539
Changes from all commits
8a66c94
fa2b583
f4939ee
a87b263
6b5f18d
37dd325
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"] |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,5 @@ | |
bin/rake | ||
.bundle | ||
.yardoc | ||
.vagrant* | ||
test/tmp | ||
Gemfile.lock |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,6 @@ namespace :test do | |
|
||
end | ||
|
||
Rake::Task["test:functional"].enhance do | ||
warn "Remember there are still some VMs running, kill them with `vagrant halt` if you are finished using them." | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗒️ |
||
end | ||
|
||
desc 'Run RuboCop lint checks' | ||
RuboCop::RakeTask.new(:lint) do |task| | ||
task.options = ['--lint'] | ||
|
This file was deleted.
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.
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 | ||
|
This file was deleted.
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 | ||
Comment on lines
+3
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗒️ This ensures that the container is cleaned up at exit. |
||
|
||
module DockerWrapper | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗒️ This code was mostly lifted from capistrano/capistrano#2159. |
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗒️
"ruby"
in this context means the latest stable version of Ruby. As of this writing, it is 3.3.3. Using this keyword means the functional tests will always run against the latest version of Ruby, without us having to manually update the workflow.