Skip to content

This repo is setup to build a dev container that can be transferred for use on an air-gapped network.

Notifications You must be signed in to change notification settings

JaimeStill/airgapped-devcontainer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Air-Gapped Dev Container

This repo is setup to build a Dev Container that can be transferred for use on an air-gapped network.

For a comprehensive discussion on creating your own air-gapped Dev Container image, refer to the Creating an Air-Gapped Dev Container document.

Steps

Back to Top

The following steps assume you are running Docker and have installed the devcontainers CLI.

  1. Pre-build the airgapped-dev Dev Container by running:

    devcontainer build --workspace-folder .\src\ --image-name airgapped-dev:latest

    devcontainer-build

  2. Make sure you have pulled the mssql/server:2022-latest image for use after disconnecting the network adapter:

    docker pull mcr.microsoft.com/mssql/server:2022-latest
  3. Open an administrative PowerShell terminal and run the Disable-AllAdapters script.

  4. Press F1 to open the command palette and select Dev Containers: Reopen in Container.

    • You can install the mssql extension after the container is built by running the following:

      code --install-extension $HOME/mssql-ubuntu-x64.vsix
  5. To cache the image for offline use, run:

    # save the image
    docker save [image]:[tag] -o [image]-[tag].tar
    
    # gzip the image tarball
    tar -czvf [image]-[tag].tar.gz [image]-[tag].tar
    
    # example
    docker save airgapped-dev:latest -o airgapped-dev-latest.tar
    tar -czvf airgapped-dev-latest.tar.gz airgapped-dev-latest.tar

    Initial builds of the image are in the range of ~4.5 GB. GZipping the image tarball will minimize the file size down to ~1.5 GB prior to transfer to the air-gapped environment.

    After transfer, the image can be extracted with:

    tar -xvf [image]-[tag].tar.gz
  6. Download the version of Visual Studio Code that corresponds to the commit in vscode-server.sh.

    You can download by commit by using the following endpoint:

    https://code.visualstudio.com/sha/download?os=[os-preference]&commit=[commit]
    

    To simplify this process, ensure the image is updated with the latest version of VS Code Server.

Update Dependencies

Back to Top

The script that generates the VS Code Server infrastructure on the Dev Container image relies on:

  • The commit string for the release of VS Code the server is being generated against.

  • The version of the VS Code SQL Server extension.

To ensure that you have the latest version of these values, make sure your local VS Code instance is up to date then run the Update-Source.ps1 script out of the scripts directory.

update-source

Composing Your Dev Environment

Back to Top

Once you have the cached Dev Container image, you can build out development environments centered around that Dev Container.

The root .devcontainer directory provides a great example of this. It assumes that you will be developing with SQL Server 2022, so it uses Docker Compose to host the official SQL Server 2022 image in a container alongside the Dev Container.

The devcontainer.json file specifies:

  • The name of the Dev Container image
  • Docker Compose metadata such as the docker compose file, the service that represents the Dev Container image, and the workspace folder.
  • Environment variables to set on the Dev Container image.
  • Forwarded ports and port attributes. In this case 1433 is configured for SQL Server.
  • VS Code extension settings to configure in the Dev Container. In this case, the connection to SQL Server is configured for the SQL Server extension.

ASP.NET Core Project Configuration

If you want to support an ASP.NET Core project, such as a Web API, that supports both local and Dev Container development, you can isolate a Container environment configuration.

In [Project]/Properties/launchSettings.json:

"profiles": {
    "development": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "launchUrl": "swagger",
        "applicationUrl": "http://localhost:5000",
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    },
    "container": {
        "commandName": "Project",
        "dotnetRunMessages": true,
        "launchBrowser": true,
        "launchUrl": "swagger",
        "applicationUrl": "http://localhost:5000",
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Container"
        }
    }
}

To connect to the container instance of SQL Server, create an appsettings.Container.json file, replacing the key and database name with your relevant values:

{
    "ConnectionStrings": {
        "[key]": "Server=localhost,1433;Encrypt=Mandatory;TrustServerCertificate=True;User=sa;Password=P@ssw0rd;Database=[database-name]"
    }    
}

The container environment can be run with:

dotnet run --launch-profile "container"

which can be aliased to a VS Code task.

Helpful Links

Back to Top

About

This repo is setup to build a dev container that can be transferred for use on an air-gapped network.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published