Skip to content
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

Feature/codespaces setup #1

Merged
merged 32 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
29b77eb
Configure GitHub Codespaces, add devcontainer.json
Sep 15, 2024
46ee8b8
Update devcontainer name
Sep 15, 2024
1f234df
Update devcontainer config for
Sep 15, 2024
a29fc82
Add Dockerfile to set up Devbox environment
Sep 15, 2024
c452148
Update devcontainer to use Dockerfile for image build
Sep 15, 2024
60ea0a5
Move Dockerfile to .devcontainer directory
Sep 15, 2024
2f1e970
Remove repository clone from Dockerfile
Sep 15, 2024
f4a8c5d
Refactor Dockerfile to separate devbox shell cmd and application tart
Sep 15, 2024
6fd4791
Fix CMD command, combine devbox shell and mvn spring-boot:run
Sep 15, 2024
caebacc
Update Dockerfile path in devcontainer.json
Sep 15, 2024
0ed03d7
Set environment variable for Devbox user
Sep 15, 2024
87771c5
Add 'devbox-user' to Dockerfile
Sep 15, 2024
82ea92f
Update remoteUser in devcontainer.json, use static value
Sep 15, 2024
b43c24e
Use root account as initial step
Sep 15, 2024
cdca497
Simplify Dockerfile, remove superfluous steps
Sep 16, 2024
67a1089
Update devcontainer config - rename remote user and add post-start cmd
Sep 16, 2024
78ac177
Add start and stop aliases to trigger mvn spring-boot commands
Sep 16, 2024
524132a
Remove terminal settings from devcontainer configuration
Sep 16, 2024
dbbe4cf
Update post-start command in devcontainer configuration to use devbox…
Sep 16, 2024
5c7e30f
Add alias to run mvn compile
Sep 16, 2024
edcaad6
Add postCreateCommand to compile sources in devbox shell
Sep 16, 2024
8f1b55c
Use Ubuntu base image, install necessary tools, nix and Devbox
Sep 16, 2024
87ec065
Add non-root user for Devbox
Sep 16, 2024
2115a22
Update Dockerfile to improve installation process
Sep 16, 2024
bf675a2
Change remote user to root in devcontainer.json
Sep 16, 2024
0e3cd35
Add redirect from root to /greeting
Sep 16, 2024
215c3be
Simplify Dockerfile by removing non-root user setup
Sep 16, 2024
ddcd4bf
Expose port 8080 in Dockerfile
Sep 16, 2024
a794244
Add static landing page
Sep 16, 2024
ee36c9e
Remove root redirect method
Sep 16, 2024
030bcdc
Remove postStartCommand
Sep 17, 2024
a81a931
Add instructions for running project via GitHub Codespaces
Sep 18, 2024
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
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Spring Boot Devbox Isolated Environment Demo",
"build": {
"dockerfile": "../Dockerfile"
},
"forwardPorts": [8080],
"remoteUser": "root",
"postCreateCommand": "devbox run compile"
}
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Use Ubuntu as the base image
FROM ubuntu:24.04

# Update package list and install essential tools (curl, ca-certificates)
RUN apt-get update && \
# Install packages without prompts and recommendations
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
curl \
ca-certificates && \
# Clean up apt cache to reduce image size
apt-get clean && \
# Delete downloaded package lists
rm -rf /var/lib/apt/lists/*

# Install Nix Package Manager using the Determinate Systems Nix installer
RUN curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install linux \
--extra-conf "sandbox = false" \
--init none \
--no-confirm

# Set PATH environment variable to include Nix binaries
ENV PATH="${PATH}:/nix/var/nix/profiles/default/bin"

# Launch systemd
CMD [ "/bin/systemd" ]

# Install Devbox using Nix
RUN nix profile install nixpkgs#devbox

# Expose port 8080 to handle requests to web server
EXPOSE 8080
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ Ensure that you have Devbox installed and configured. Devbox manages the depende

### Steps to Run

#### Option 1: Locally

1. **Clone the repository**
```bash
git clone https://github.com/eth-library/devbox-spring-demo.git
Expand All @@ -44,6 +46,25 @@ Ensure that you have Devbox installed and configured. Devbox manages the depende
```bash
curl "http://localhost:8080/greeting?name=Devbox%20Tester"

#### Option 2: Using GitHub Codespaces

1. Fork this repository

2. From the **Code** dropdown, select **Create codespace on main**

3. Once the codespace has loaded, run `devbox run start` in the terminal to start the webserver.

```bash
devbox run start
```

4. When prompted, click **Open in Browser**.

> [!TIP]
> If the popup is not visible, you can navigate to the **Forwarded Ports** tab, and open the **Forwarded Address** for port 8080.

5. **Success!** You'll see the landing page and can now curl the greeting endpoint!

## Custom Maven Settings

To maintain an isolated environment, a custom `maven.config` file is provided in the `.mvn` directory. This configuration ensures that all Maven dependencies are stored locally within the project rather than in a global repository. This approach helps to keep the development environment fully isolated, avoiding any interference from global dependencies.
9 changes: 9 additions & 0 deletions devbox.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,17 @@
"echo 'Welcome to devbox!' > /dev/null"
],
"scripts": {
"compile": [
"mvn compile"
],
"test": [
"mvn test"
],
"start": [
"mvn spring-boot:start"
],
"stop": [
"mvn spring-boot:stop"
]
}
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/resources/static/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Devbox Spring Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<p>Hi there!</p>
<p>The webserver was started to serve the Devbox Spring Demo application.</p>
<p>Visit or curl the <a href="/greeting">greeting endpoint</a> to test the API.</p>
<p>Refer to the <a href="https://github.com/eth-library/devbox-spring-demo">GitHub repository</a> for more information.</p>
</body>
</html>
Loading