Skip to content

Remove unused CI files and provide a devcontainer setup #587

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

Merged
merged 2 commits into from
Jun 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM mcr.microsoft.com/devcontainers/ruby:2.7

# Install the SQL Server command-line tools and the Artistic Style code formatter
RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc \
&& curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list \
&& apt-get update \
&& ACCEPT_EULA=Y apt-get install -y astyle mssql-tools18 unixodbc-dev
ENV PATH=$PATH:/opt/mssql-tools18/bin

# Install FreeTDS
ENV FREETDS_VERSION=1.5.1
COPY test/bin/install-freetds.sh /tmp/
RUN /tmp/install-freetds.sh

# Add the tiny_tds main Gemfile and install the gems.
RUN mkdir -p /tmp/tiny_tds
COPY Gemfile VERSION tiny_tds.gemspec /tmp/tiny_tds/
RUN cd /tmp/tiny_tds \
&& bundle install \
&& rm -rf /tmp/tiny_tds
RUN chown -R vscode:vscode /usr/local/rvm && chown -R vscode:vscode /usr/local/bundle
6 changes: 6 additions & 0 deletions .devcontainer/boot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Setup test databases and users.
sqlcmd -C -S sqlserver -U sa -P 'c0MplicatedP@ssword' -i ./test/sql/db-create.sql
sqlcmd -C -S sqlserver -U sa -P 'c0MplicatedP@ssword' -i ./test/sql/db-login.sql

# Mark directory as safe in Git so that commands run without warnings.
git config --global --add safe.directory /workspaces/tiny_tds
40 changes: 40 additions & 0 deletions .devcontainer/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: '3'

services:
tiny_tds:
build:
context: ..
dockerfile: .devcontainer/Dockerfile

volumes:
- ../..:/workspaces:cached

# Overrides default command so things don't shut down after the process ends.
command: sleep infinity

networks:
- default
depends_on:
- sqlserver

toxiproxy:
image: ghcr.io/shopify/toxiproxy:2.5.0

sqlserver:
image: mcr.microsoft.com/mssql/server:2022-latest
restart: unless-stopped
networks:
- default
volumes:
- sqlserver-data:/var/opt/mssql
ports:
- "1433:1433"
environment:
MSSQL_SA_PASSWORD: 'c0MplicatedP@ssword'
ACCEPT_EULA: Y

networks:
default:

volumes:
sqlserver-data:
30 changes: 30 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// For format details, see https://aka.ms/devcontainer.json.
{
"name": "tiny_tds project development",
"dockerComposeFile": "compose.yaml",
"service": "tiny_tds",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

// Features to add to the dev container. More info: https://containers.dev/features.
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {
// Moby is not installable in Debian 11
"moby": false
}
},

"containerEnv": {
"TINYTDS_UNIT_HOST": "sqlserver",
"TOXIPROXY_HOST": "toxiproxy"
},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// This can be used to network with other containers or the host.
// "forwardPorts": [3000, 5432],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": ".devcontainer/boot.sh",

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
40 changes: 12 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,42 +401,26 @@ First, clone the repo using the command line or your Git GUI of choice.
$ git clone [email protected]:rails-sqlserver/tiny_tds.git
```

After that, the quickest way to get setup for development is to use [Docker](https://www.docker.com/). Assuming you have [downloaded docker](https://www.docker.com/products/docker) for your platform, you can use [docker-compose](https://docs.docker.com/compose/install/) to run the necessary containers for testing.
After that, the quickest way to get setup for development is to use the provided devcontainers setup.

```shell
$ docker-compose up -d
npm install -g @devcontainers/cli
devcontainer up --workspace-folder .
devcontainer exec --workspace-folder . bash
```

This will download the official SQL Server for Linux Docker image from [Microsoft](https://hub.docker.com/r/microsoft/mssql-server-linux/). This will also download a [toxiproxy](https://github.com/shopify/toxiproxy) Docker image which we can use to simulate network failures for tests. Basically, it does the following:
From within the container, you can run the tests using the following command:

```shell
$ docker network create main-network
$ docker pull mcr.microsoft.com/mssql/server:2017-latest
$ docker run -p 1433:1433 -d --name sqlserver --network main-network mcr.microsoft.com/mssql/server:2017-latest
$ docker pull shopify/toxiproxy
$ docker run -p 8474:8474 -p 1234:1234 -d --name toxiproxy --network main-network shopify/toxiproxy
bundle install
bundle exec rake test
```

Make sure to run these SQL scripts as SA to get the test database and user installed. If needed, install [sqlcmd as described by Microsoft for your platform](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16&tabs=go%2Clinux&pivots=cs1-bash).
You can customize the environment variables to run the tests against a different environment

```shell
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P super01S3cUr3 -i ./test/sql/db-create.sql
/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P super01S3cUr3 -i ./test/sql/db-login.sql
```

From here you can build and run tests against an installed version of FreeTDS.

```shell
$ bundle install
$ bundle exec rake
```

Examples us using enviornment variables to customize the test task.

```
$ rake TINYTDS_UNIT_DATASERVER=mydbserver
$ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2017
$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
```shell
rake test TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2017
rake test TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
```

### Code formatting
Expand All @@ -450,7 +434,7 @@ We are using `standardrb` to format the Ruby code and Artistic Style for the C c

For the convenience, TinyTDS ships pre-compiled gems for supported versions of Ruby on Windows and Linux. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used.

Run the following rake task to compile the gems. This will check the availability of [Docker](https://www.docker.com/) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:
Run the following rake task to compile the gems. You can run these commands from inside the devcontainers setup, or outside if neeed. The command will check the availability of [Docker](https://www.docker.com/) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:

```shell
bundle exec rake gem:native
Expand Down
34 changes: 0 additions & 34 deletions docker-compose.yml

This file was deleted.

25 changes: 0 additions & 25 deletions setup_cimgruby_dev.sh

This file was deleted.

21 changes: 0 additions & 21 deletions start_dev.sh

This file was deleted.

42 changes: 0 additions & 42 deletions test/bin/install-mssql.ps1

This file was deleted.

9 changes: 0 additions & 9 deletions test/bin/install-mssqltools.sh

This file was deleted.

18 changes: 0 additions & 18 deletions test/bin/install-openssl.sh

This file was deleted.

7 changes: 0 additions & 7 deletions test/bin/setup_tinytds_db.sh

This file was deleted.

10 changes: 0 additions & 10 deletions test/bin/setup_volume_permissions.sh

This file was deleted.

4 changes: 2 additions & 2 deletions tiny_tds.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
require "tiny_tds/version"
version = File.read(File.expand_path("VERSION", __dir__)).strip

Gem::Specification.new do |s|
s.name = "tiny_tds"
s.version = TinyTds::VERSION
s.version = version
s.platform = Gem::Platform::RUBY
s.authors = ["Ken Collins", "Erik Bryn", "Will Bond"]
s.email = ["[email protected]", "[email protected]"]
Expand Down