Skip to content

Commit 43383ed

Browse files
committed
Update project to use new content repo layout & other minor tweaks
1 parent 34fc456 commit 43383ed

16 files changed

Lines changed: 249 additions & 218 deletions

.github/workflows/publish-labspace.yaml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,13 @@ jobs:
1515
- name: Checkout code
1616
uses: actions/checkout@v4
1717

18-
# Ensure Compose v2.39.3+ is available (includes bug fixes for publishing)
19-
# Can remove this action once default runners include it
20-
- name: Set up Docker Compose
21-
uses: docker/setup-compose-action@v1
22-
with:
23-
version: v2.39.3
24-
2518
- name: Log in to DockerHub
2619
uses: docker/login-action@v3
2720
with:
2821
username: ${{ secrets.DOCKERHUB_USERNAME }}
2922
password: ${{ secrets.DOCKERHUB_TOKEN }}
3023

31-
- name: Publish Compose file
32-
run: |
33-
docker compose -f oci://dockersamples/labspace -f .labspace/compose.override.yaml publish ${DOCKERHUB_REPO} --with-env -y
24+
- name: Publish Labspace
25+
uses: dockersamples/publish-labspace-action@v2
26+
with:
27+
target_repo: ${{ env.DOCKERHUB_REPO }}

.labspace/04-your-first-testcontainers-integration.md

Lines changed: 0 additions & 102 deletions
This file was deleted.

README.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,52 @@
1-
# Labspace starter
1+
# Labspace - Introduction to Testcontainers - Java
22

3-
This repository is intended to server as a template to help bootstrap a new Labspace.
3+
Containers can be used for more than simply running your application. With Testcontainers, you can use containers to easily start the services needed by your application.
44

5-
## Instructions
5+
In this Labspace, you'll learn how to use Testcontainers in a Spring-based application.
66

7-
1. Create a new repository using this repo as the template ([docs here](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template)).
7+
## Learning objectives
88

9-
**NOTE:** After creating the repo, a GHA workflow will run to do some additional bootstrapping. The bootstrapping workflow file will be removed during bootstrapping.
9+
By the end of this Labspace, you will have learned the following:
1010

11-
2. Clone your newly created repo to your local machine
11+
- Write end-to-end API tests using real services instead of mocks
12+
- How to autowire Spring config to use containerized databases
13+
- How to use GenericContainer to provide additional services and wire them with `@DynamicPropertySource`
1214

13-
3. Start the local development mode:
15+
## Launch the Labspace
1416

15-
```bash
16-
# On Mac/Linux
17-
CONTENT_PATH=$PWD docker compose -f oci://dockersamples/labspace-content-dev -f .labspace/compose.override.yaml up
17+
To launch the Labspace, run the following command:
1818

19-
# On Windows with PowerShell
20-
$Env:CONTENT_PATH = (Get-Location).Path; docker compose -f oci://dockersamples/labspace-content-dev -f .labspace/compose.override.yaml up
21-
```
19+
```bash
20+
docker compose -f oci://dockersamples/labspace-testcontainers-java up -d
21+
```
2222

23-
4. Update the `labspace.yaml` with your Labspace's title and description
23+
And then open your browser to http://localhost:3030.
2424

25-
5. Write your Labspace! Being in dev mode, your changes should be visible in the interface without a restart. Feel free to edit either on your host machine or in the Labspace itself!
25+
### Using the Docker Desktop extension
2626

27-
Add any supporting application files or resources directly into the Labspace. This repo will be cloned into the Labspace at startup.
27+
If you have the Labspace extension installed (`docker extension install dockersamples/labspace-extension` if not), you can also [click this link](https://open.docker.com/dashboard/extension-tab?extensionId=dockersamples/labspace-extension&location=dockersamples/labspace-testcontainers-javaimages&title=Introduction%20to%20Testcontainers%20-%20Java) to launch the Labspace.
2828

29-
Be sure to check out the [docs](https://github.com/dockersamples/labspace-infra/tree/main/docs) for additional information and guidelines.
3029

30+
## Contributing
3131

32+
If you find something wrong or something that needs to be updated, feel free to submit a PR. If you want to make a larger change, feel free to fork the repo into your own repository.
3233

33-
### Setting up the deployment pipeline
34+
**Important note:** If you fork it, you will need to update the GHA workflow to point to your own Hub repo.
3435

35-
The template repo contains a workflow file to make it easy to publish your Labspace.
36+
1. Clone this repo
3637

37-
1. Add GitHub Action Secrets in your new repo for the following:
38+
2. Start the Labspace in content development mode:
3839

39-
- `DOCKERHUB_USERNAME` - the username to authenticate to Docker Hub with
40-
- `DOCKERHUB_TOKEN` - a personal or organization access token to use for authentication
40+
```bash
41+
# On Mac/Linux
42+
CONTENT_PATH=$PWD docker compose up --watch
4143

42-
2. In the `.github/workflows/publish-labspace.yaml.temp` file, update the `DOCKERHUB_REPO` with the name of the Docker Hub repo you want to publish to.
44+
# On Windows with PowerShell
45+
$Env:CONTENT_PATH = (Get-Location).Path; docker compose up --watch
46+
```
4347

44-
3. Rename the workflow file to remove the `.temp` extension.
48+
3. Open the Labspace at http://localhost:3030.
4549

46-
```bash
47-
mv .github/workflows/publish-labspace.yaml.temp .github/workflows/publish-labspace.yaml
48-
```
50+
4. Make the necessary changes and validate they appear as you expect in the Labspace
51+
52+
Be sure to check out the [docs](https://github.com/dockersamples/labspace-infra/tree/main/docs) for additional information and guidelines.

compose.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include:
2+
- oci://dockersamples/labspace-content-dev:latest-sdlc
3+
- ./compose.override.yaml

labspace.yaml

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ git clone https://github.com/testcontainers/workshop.git
66
```
77

88
## Build the project to download the dependencies
9+
910
Switch to the workshop folder:
11+
1012
```bash
1113
cd workshop
1214
```
15+
1316
and build the project with Maven:
17+
1418
```bash
1519
./mvnw verify
16-
```
20+
```
File renamed without changes.
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ But before we write our first test, let's create an abstract test class for the
55

66
## Abstract class
77

8-
Add `AbstractIntegrationTest` class to `src/test/java` sourceset.
8+
Add `AbstractIntegrationTest` class to `src/test/java` sourceset.
9+
910
It will be an abstract class with standard Spring Boot's testing framework annotations on it:
11+
1012
```java save-as=workshop/src/test/java/com/example/demo/AbstractIntegrationTest.java
1113
package com.example.demo;
1214

@@ -36,18 +38,21 @@ public class DemoApplicationTest extends AbstractIntegrationTest{
3638
```
3739

3840
Run it and verify that the application starts and the test passes.
41+
3942
```bash
4043
./mvnw clean test
4144
```
45+
4246
Spring will detect H2 on the classpath and use it as an embedded DB.
4347

4448
This is already a useful smoke test since it ensures, that Spring Boot is able to initialize the application context successfully.
4549

4650
## Populate the database
4751

48-
The context starts.
49-
However, we need to populate the database with some data before we can write the tests.
52+
The Spring context starts. However, we need to populate the database with some data before we can write the tests.
53+
5054
Let's add a `schema.sql` file with the following content:
55+
5156
```sql save-as=workshop/src/test/resources/schema.sql
5257
CREATE TABLE IF NOT EXISTS talks(
5358
id VARCHAR(64) NOT NULL,
@@ -67,9 +72,11 @@ INSERT
6772
```
6873

6974
Now run the test again.
75+
7076
```bash
7177
./mvnw clean test
7278
```
79+
7380
Oh no, it fails!
7481

7582
```plaintext

0 commit comments

Comments
 (0)