Development with DevContainers
Overview
This guide explains how to set up and use DevContainers for local development of the Performance Automation Framework. DevContainers provide a consistent, isolated environment for development that includes all necessary dependencies and tools pre-configured, ensuring compatibility with Java 21 and all required script engines.
Prerequisites
- Docker Desktop installed on your system
- Visual Studio Code installed
- Remote Development extension pack installed in VS Code
DevContainer Configuration
The Performance Automation Framework includes a pre-configured DevContainer setup in the .devcontainer
directory, which provides:
- Java 21 (OpenJDK) with required script engines
- Maven 3.9.6
- JMeter 5.6 with DSL integration
- Script engines (Groovy 4.0.15 and Nashorn 15.4)
- All required dependencies and tools for development
- Pre-configured VS Code extensions for Java, Maven, and testing
Getting Started with DevContainers
Step 1: Clone the Repository
git clone https://github.com/TestAutomationMultiverse/PerformanceAutomationFramework.git
cd PerformanceAutomationFramework
Step 2: Open in VS Code
Open the project folder in Visual Studio Code:
Step 3: Reopen in Container
When you open the project for the first time, VS Code should detect the DevContainer configuration and prompt you to reopen the project in a container. If not, you can:
- Press
F1
to open the command palette - Type "Remote-Containers: Reopen in Container" and select it
VS Code will build the container (this may take a few minutes the first time) and then reopen the project inside the container environment.
Using the DevContainer Environment
Once inside the DevContainer, you'll have access to:
- A terminal with all necessary command-line tools
- Pre-configured Java and Maven settings
- Extensions for Java development pre-installed
- Consistent environment matching CI/CD pipelines
Running Tests
You can run tests directly from the integrated terminal:
Building the Project
To build the entire project:
Debugging Tests
- Set breakpoints in your Java code
- Go to the Run and Debug view (
Ctrl+Shift+D
) - Select "Debug JUnit Test" from the dropdown
- Press F5 to start debugging
DevContainer Customization
Adding Dependencies
If you need additional dependencies, you can:
- Modify the
pom.xml
file to add Java dependencies - Modify the
.devcontainer/Dockerfile
to add system dependencies
After modifying the Dockerfile, you'll need to rebuild the container:
- Press
F1
to open the command palette - Type "Remote-Containers: Rebuild Container" and select it
Customizing VS Code Settings
The DevContainer configuration includes VS Code settings specific to the container environment. You can customize these in:
.devcontainer/devcontainer.json
: Container configuration.devcontainer/settings.json
: VS Code settings for the container
Troubleshooting
Container Build Fails
If the container build fails, check:
- Docker Desktop is running
- You have sufficient disk space
- The Docker daemon has sufficient resources allocated (memory/CPU)
Performance Issues
If experiencing slow performance:
- Increase the resources allocated to Docker in Docker Desktop settings
- Consider using volume mounts for large directories like
.m2/repository
Java 21 and Script Engine Issues
The framework requires Java 21 and specific script engines. If experiencing issues:
- Check the Java version inside the container:
java -version
(should be 21+) - Verify script engines are available:
- Ensure all dependencies are correctly installed:
- Check that both Nashorn and Groovy dependencies are present in your POM file
Advanced Usage
Running with Specific JMeter Properties
To run tests with specific JMeter properties:
Using Shared Maven Repository
To speed up builds by sharing the Maven repository with your host:
// In devcontainer.json
"mounts": [
"source=${localEnv:HOME}/.m2,target=/root/.m2,type=bind,consistency=cached"
]
Creating a DevContainer Setup
If you're working with a fresh clone of the repository that doesn't have a DevContainer configuration yet, follow these steps to create one:
Step 1: Generate DevContainer Files
- In VS Code, press
F1
and search for "Remote-Containers: Add Development Container Configuration Files..." - Select "Java" from the list of container templates
- Select the latest Java version (21)
- Select any additional features you want to add (Maven, Git, etc.)
- This will create a
.devcontainer
directory in your project
Step 2: Customize the Dockerfile
Edit .devcontainer/Dockerfile
to include the following:
FROM mcr.microsoft.com/devcontainers/java:1-21-bullseye
# Install Maven
ARG MAVEN_VERSION=3.9.6
RUN su vscode -c "umask 0002 && . /usr/local/sdkman/bin/sdkman-init.sh && sdk install maven \"${MAVEN_VERSION}\""
# Set up a non-root user
USER vscode
# Install required packages for JMeter and the framework
RUN mkdir -p /home/vscode/.m2
COPY pom.xml /tmp/
WORKDIR /tmp
RUN mvn dependency:go-offline
# Set the working directory
WORKDIR /workspaces/performance-automation-framework
Step 3: Configure devcontainer.json
Edit the .devcontainer/devcontainer.json
file to include Java extensions and settings:
{
"name": "Java Performance Testing",
"dockerFile": "Dockerfile",
"extensions": [
"vscjava.vscode-java-pack",
"vscjava.vscode-maven",
"redhat.java",
"ms-azuretools.vscode-docker",
"streetsidesoftware.code-spell-checker"
],
"settings": {
"java.server.launchMode": "Standard",
"java.configuration.updateBuildConfiguration": "automatic",
"maven.executable.path": "/usr/local/sdkman/candidates/maven/current/bin/mvn"
},
"remoteUser": "vscode"
}
Conclusion
Using DevContainers provides a consistent, reproducible environment for development that closely matches the CI/CD and production environments. This helps eliminate "works on my machine" issues and streamlines onboarding for new developers.
The Performance Automation Framework with Java 21 compatibility requires specific dependencies and configurations that are automatically included in the DevContainer setup, making it easier to get started with development without worrying about script engine compatibility issues.