Skip to content

Commit

Permalink
Update Docker Hub readme & dependabot config (#195)
Browse files Browse the repository at this point in the history
* Update Docker Hub readme & dependabot config

* Add remote config loader

* Adjust tests

* Add web request security issue to ignore list

* Add more tests

* Fix bug

* Adjust documentation
  • Loading branch information
marcauberer committed Oct 30, 2021
1 parent 9f6c00b commit 813ce70
Show file tree
Hide file tree
Showing 14 changed files with 341 additions and 152 deletions.
8 changes: 4 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ updates:
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 15
target-branch: release/v1.2.x
target-branch: release/v1.3.x
reviewers:
- marcauberer
assignees:
Expand All @@ -22,7 +22,7 @@ updates:
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 15
target-branch: release/v1.2.x
target-branch: release/v1.3.x
reviewers:
- marcauberer
assignees:
Expand All @@ -36,7 +36,7 @@ updates:
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 15
target-branch: release/v1.2.x
target-branch: release/v1.3.x
reviewers:
- marcauberer
assignees:
Expand All @@ -50,7 +50,7 @@ updates:
time: "04:00"
timezone: Europe/Berlin
open-pull-requests-limit: 15
target-branch: release/v1.2.x
target-branch: release/v1.3.x
reviewers:
- marcauberer
assignees:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ jobs:
run: bash <(curl -s https://codecov.io/bash)

- name: Install GoSec
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/v2.8.1/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.8.1
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/v2.9.1/install.sh | sh -s -- -b $(go env GOPATH)/bin v2.9.1

- name: Run security scan
working-directory: src
run: gosec ./...
run: gosec -exclude=G307 ./...
16 changes: 8 additions & 8 deletions docs/docs/usage/generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ You can use the `generate` command to generate Docker Compose configurations. Th
## Options
You can apply following options to the `generate` command:

| Option | Short | Description |
| --------------------- | ----------- | ------------------------------------------------------------------------- |
| `--advanced` | `-a` | Enable advanced mode with advanced questions to allow more customization. |
| `--config <file>` | `-c <file>` | Pass a configuration file with predefined answers. Works good for CI.[^1] |
| `--detached` | `-d` | Run the compose configuration subsequently in detached mode. |
| `--force` | `-f` | Skip safety checks and overwrite all files, that may exist. |
| `--run` | `-r` | Run the compose configuration subsequently. |
| `--with-instructions` | `-i` | Generate a README.md file with usage instruction for predefined template. |
| Option | Short | Description |
| --------------------- | --------------- | ------------------------------------------------------------------------------------ |
| `--advanced` | `-a` | Enable advanced mode with advanced questions to allow more customization. |
| `--config <resource>` | `-c <resource>` | Pass a config file / config file URL with predefined answers. Works good for CI.[^1] |
| `--detached` | `-d` | Run the compose configuration subsequently in detached mode. |
| `--force` | `-f` | Skip safety checks and overwrite all files, that may exist. |
| `--run` | `-r` | Run the compose configuration subsequently. |
| `--with-instructions` | `-i` | Generate a README.md file with usage instruction for predefined template. |

[^1]:
You can find an example configuration file [here](https://github.com/compose-generator/compose-generator/blob/main/media/example-config.yml).
2 changes: 0 additions & 2 deletions media/example-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ services:
- name: angular
type: frontend
params:
ANGULAR_SOURCE_DIRECTORY: ./frontend-angular
ANGULAR_PORT: 81
- name: spring-maven
type: backend
params:
SPRING_MAVEN_SOURCE_DIRECTORY: ./backend-spring
SPRING_MAVEN_PORT: 8081
SPRING_MAVEN_VERSION: 2.4.3.RELEASE
SPRING_MAVEN_LANGUAGE: groovy
Expand Down
3 changes: 2 additions & 1 deletion media/readme-dockerhub.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
- **Where to get help:** [Official Website](https://www.compose-generator.com), [GitHub](https://github.com/compose-generator/compose-generator)

## Supported tags and respective `Dockerfile` links
- `1.1.0`, `1.1`, `1`, `latest`
- `1.2.0`, `1.2`, `1`, `latest`
- `1.1.0`, `1.1`
- `1.0.0`

## Quick reference (cont.)
Expand Down
2 changes: 1 addition & 1 deletion src/pass/generate/gen_add_proxy_networks.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

// GenerateAddProxyNetworks connects all proxied services via networks to the proxy and removes their port configs
func GenerateAddProxyNetworks(project *model.CGProject, selectedTemplates *model.SelectedTemplates) {
if project.ProductionReady {
if project.ProductionReady && len(selectedTemplates.ProxyServices) > 0 {
infoLogger.Println("Adding proxy networks to proxied services ...")
// Get reference of proxy service
proxyService := project.GetServiceRef("proxy-" + selectedTemplates.ProxyServices[0].Name)
Expand Down
12 changes: 12 additions & 0 deletions src/pass/generate/gen_add_proxy_networks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ func TestGenerateAddProxyNetworks2(t *testing.T) {
}

func TestGenerateAddProxyNetworks3(t *testing.T) {
// Test data
project := &model.CGProject{
CGProjectMetadata: model.CGProjectMetadata{
ProductionReady: true,
},
}
selectedTemplates := &model.SelectedTemplates{}
// Execute test
GenerateAddProxyNetworks(project, selectedTemplates)
}

func TestGenerateAddProxyNetworks4(t *testing.T) {
// Test data
project := &model.CGProject{
CGProjectMetadata: model.CGProjectMetadata{
Expand Down
91 changes: 64 additions & 27 deletions src/pass/generate/gen_load_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ import (
"strings"
)

var loadConfigFromUrlMockable = loadConfigFromUrl
var loadConfigFromFileMockable = loadConfigFromFile

// ---------------------------------------------------------------- Public functions ---------------------------------------------------------------

// LoadGenerateConfig loads a generate configuration from a file
func LoadGenerateConfig(project *model.CGProject, config *model.GenerateConfig, configPath string) {
if configPath == "" {
func LoadGenerateConfig(project *model.CGProject, config *model.GenerateConfig, configInput string) {
if configInput == "" {
// Welcome Message
heading("Welcome to Compose Generator! 馃憢")
pl("Please continue by answering a few questions:")
Expand All @@ -33,33 +36,13 @@ func LoadGenerateConfig(project *model.CGProject, config *model.GenerateConfig,
config.FromFile = false
infoLogger.Println("Production-ready: '" + strconv.FormatBool(config.ProductionReady) + "'")
} else {
// Take the given config file and load config from there
if fileExists(configPath) {
infoLogger.Println("Config file was attached")
yamlFile, err := openFile(configPath)
if err != nil {
errorLogger.Println("Could not load config file: " + err.Error())
logError("Could not load config file. Permissions granted?", true)
return
}
content, err := readAllFromFile(yamlFile)
if err != nil {
errorLogger.Println("Could not load config file: " + err.Error())
logError("Could not load config file. Permissions granted?", true)
return
}
// Parse yaml
if err := unmarshalYaml(content, &config); err != nil {
errorLogger.Println("Could not unmarshal config file: " + err.Error())
logError("Could not unmarshal config file", true)
return
}
config.FromFile = true
// Check if the input is an url
if isUrl(configInput) {
loadConfigFromUrlMockable(config, configInput)
} else {
errorLogger.Println("Config file could not be found")
logError("Config file could not be found", true)
return
loadConfigFromFileMockable(config, configInput)
}
config.FromFile = true
}

project.Name = config.ProjectName
Expand All @@ -71,3 +54,57 @@ func LoadGenerateConfig(project *model.CGProject, config *model.GenerateConfig,
project.Vars["PROJECT_NAME"] = project.Name
project.Vars["PROJECT_NAME_CONTAINER"] = project.ContainerName
}

// --------------------------------------------------------------- Private functions ---------------------------------------------------------------

func loadConfigFromFile(config *model.GenerateConfig, configPath string) {
// Take the given config file and load config from there
if fileExists(configPath) {
infoLogger.Println("Config file was attached")
yamlFile, err := openFile(configPath)
if err != nil {
errorLogger.Println("Could not load config file: " + err.Error())
logError("Could not load config file. Permissions granted?", true)
return
}
content, err := readAllFromFile(yamlFile)
if err != nil {
errorLogger.Println("Could not load config file: " + err.Error())
logError("Could not load config file. Permissions granted?", true)
return
}
// Parse yaml
if err := unmarshalYaml(content, &config); err != nil {
errorLogger.Println("Could not unmarshal config file: " + err.Error())
logError("Could not unmarshal config file", true)
return
}
} else {
errorLogger.Println("Config file could not be found")
logError("Config file could not be found", true)
}
}

func loadConfigFromUrl(config *model.GenerateConfig, configUrl string) {
// Make web request
// #nosec G107
response, err := httpGet(configUrl)
if err != nil {
errorLogger.Println("Config url could not be read")
logError("Config url could not be read", true)
return
}
defer response.Body.Close()
// Read response
bytes, err := readAllFromFile(response.Body)
if err != nil {
errorLogger.Println("Could not parse yaml")
logError("Could not parse yaml", true)
return
}
// Parse yaml
if err := unmarshalYaml(bytes, &config); err != nil {
errorLogger.Println("Could not unmarshal config file: " + err.Error())
logError("Could not unmarshal config file", true)
}
}

0 comments on commit 813ce70

Please sign in to comment.