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

Copyonwrite/248/add devcontainer setup #286

Merged
merged 14 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

FROM mcr.microsoft.com/devcontainers/go

WORKDIR /go/src/github.com/cloudoperators/heureka
ADD . .
11 changes: 11 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "heureka & MariaDB",
"dockerComposeFile": "docker-compose.yml",
"service": "app",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"postCreateCommand": "make",
"forwardPorts": [
80,
"mariadb:3306"
]
}
47 changes: 47 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

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

volumes:
- ../..:/workspaces:cached
- ../internal/database/mariadb/init/schema.sql:/app_sqlschema/schema.sql

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

# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
network_mode: service:mariadb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to remove this line on IntelliJ to make the dev-container start


environment:
# MariaDB Connection
DB_ADDRESS: mariadb
DB_PORT: 3306
DB_USER: mariadb
DB_PASSWORD: mariadb
DB_ROOT_PASSWORD: mariadb
DB_NAME: heureka
DB_SCHEMA: /app_sqlschema/schema.sql


SEED_MODE: true
AUTH_TYPE: token
AUTH_TOKEN_SECRET: xxx

mariadb:
image: mariadb:latest
container_name: mariadb
restart: unless-stopped

environment:
MARIADB_USER: mariadb
MARIADB_PASSWORD: mariadb
MARIADB_DATABASE: heureka
MARIADB_ROOT_PASSWORD: mariadb

volumes:
- ../.mariadb-dev/:/var/lib/mysql
18 changes: 18 additions & 0 deletions .env-devcontainer
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Greenhouse contributors
# SPDX-License-Identifier: Apache-2.0

DB_USER=mariadb
DB_PASSWORD=mariadb
DB_ROOT_PASSWORD=mariadb
DB_NAME=heureka
DB_ADDRESS=mariadb
DB_PORT=3306
DB_SCHEMA=internal/database/mariadb/init/schema.sql

DB_CONTAINER_IMAGE=mariadb:latest

LOG_PRETTY_PRINT=true

LOCAL_TEST_DB=true

SEED_MODE=true
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
# vendor/
.vscode
.DS_Store
cmd/heureka/__debug_bin*

# Heureka specifics
build/
.db/
.env
.env
.mariadb-dev/
49 changes: 49 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch K8sScanner",
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}",
"program": "scanner/k8s-assets/main.go",
"envFile": "${workspaceFolder}/scanner/k8s-assets/.env"
},
{
"name": "Launch NvdScanner",
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}",
"program": "scanner/nvd/main.go",
"envFile": "${workspaceFolder}/scanner/nvd/.env"
},
{
"name": "Launch KeppelScanner",
"type": "go",
"request": "launch",
"mode": "auto",
"cwd": "${workspaceFolder}",
"program": "scanner/keppel/main.go",
"envFile": "${workspaceFolder}/scanner/keppel/.env"
},
{
"name": "Launch Heureka DevContainer",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "cmd/heureka/main.go",
"args": [
"-mode",
"seed"
],
"cwd": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env-devcontainer",
"showLog": true
}
]
}
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,37 @@ docker-compose --profile db --profile heureka up

### Makefile

Alternatively, the application can be started by using the provided Makefile:
The application can be started by using the provided Makefile:

```
make start-all-heureka
```

### Devcontainers
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requirements would be helpful:

Which Docker environements is the expected to work on?

e.g.: Does it also work with Podman?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also:

If we decide not to investigate the Intellij/OSX combination, we may add to the documentation on which systems this setup is recommended/working.


Devcontainers is a new standard for development environments based on (docker)
[devcontainer](./.devcontainer).

At the moment devcontainers are supported by Visual Studio Code and IDEA IDEs.

For Microsoft Visual Studio code, install the remote container extension via
Ctrl-P and this command:

ext install ms-vscode-remote.remote-containers

When opening the root folder in Visual Studio code a prompt will ask you to
open the project in a dev container, which you should.

Once inside the devcontainer the provided launch.json is configured to allow
launching heureka and running the unit and integration tests.

At the moment there is a known issue with the permissions of the .mariadb-dev
folder. This folder has to be deleted every time after using the devcontainers.
Use the following command in the root folder of heureka:

sudo rm -rf .mariadb-dev


### Tests

#### Mockery
Expand Down
Loading