Skip to content

Commit

Permalink
Merge pull request #72 from openhie/package-generate-update
Browse files Browse the repository at this point in the history
Update and fix package generate command
  • Loading branch information
rcrichton authored Sep 27, 2024
2 parents 7e4c274 + 1f480de commit 966c3f5
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 50 deletions.
6 changes: 3 additions & 3 deletions cli/src/cmd/pkg/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"os"
"path"
"path/filepath"

"cli/core/generate"
"cli/core/prompt"
Expand All @@ -27,13 +26,14 @@ func packageGenerateCommand() *cobra.Command {
panic(err)
}

ex, err := os.Executable()
// Get the current working directory
cwd, err := os.Getwd()
if err != nil {
log.Error(ctx, err)
panic(err)
}

packagePath := path.Join(filepath.Dir(ex), resp.Id)
packagePath := path.Join(cwd, resp.Id)
err = os.Mkdir(packagePath, os.ModePerm)
if err != nil {
log.Error(ctx, err)
Expand Down
2 changes: 1 addition & 1 deletion cli/src/cmd/version/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.3.2
2.4.0
1 change: 0 additions & 1 deletion cli/src/core/generate/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ func Test_createFileFromTemplate(t *testing.T) {
generatePackSpec := core.GeneratePackageSpec{
Id: "test-package",
Name: "Test Package",
Stack: "test-stack",
Image: "test/image",
Description: "A package for testing",
Type: "infrastructure",
Expand Down
15 changes: 5 additions & 10 deletions cli/src/core/generate/template/package/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare ACTION=""
declare MODE=""
declare COMPOSE_FILE_PATH=""
declare UTILS_PATH=""
declare SERVICE_NAMES=()
declare STACK="{{.Id}}"

function init_vars() {
ACTION=$1
Expand All @@ -17,15 +17,11 @@ function init_vars() {

UTILS_PATH="${COMPOSE_FILE_PATH}/../utils"

SERVICE_NAMES=(
"{{.Id}}"
)

readonly ACTION
readonly MODE
readonly COMPOSE_FILE_PATH
readonly UTILS_PATH
readonly SERVICE_NAMES
readonly STACK
}

# shellcheck disable=SC1091
Expand All @@ -44,16 +40,15 @@ function initialize_package() {
fi

(
docker::deploy_service "${COMPOSE_FILE_PATH}" "$package_dev_compose_filename"
docker::deploy_sanity "${SERVICE_NAMES[@]}"
docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$package_dev_compose_filename"
) || {
log error "Failed to deploy package"
exit 1
}
}

function destroy_package() {
docker::service_destroy "${SERVICE_NAMES[@]}"
docker::stack_destroy $STACK
}

main() {
Expand All @@ -67,7 +62,7 @@ main() {
elif [[ "${ACTION}" == "down" ]]; then
log info "Scaling down package"

docker::scale_services_down "${SERVICE_NAMES[@]}"
docker::scale_services $STACK 0
elif [[ "${ACTION}" == "destroy" ]]; then
log info "Destroying package"

Expand Down
29 changes: 8 additions & 21 deletions cli/src/core/prompt/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ package prompt

import (
"cli/core"
"fmt"

"github.com/iancoleman/strcase"
"github.com/luno/jettison/errors"
"github.com/manifoldco/promptui"
)
Expand All @@ -15,11 +13,10 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
What is the name of your package:
What docker image would you like to use with this project:
Provide a description of your package:
Which stack does your package belong to:
What type best suites your package:
Do you want to include a dev compose file:
Which port would you like to target in dev mode:
Which port would you like published in dev mode:
Which port would you like to target on the container in dev mode:
Which port would you like published on the host in dev mode:
*/

promptId := promptui.Prompt{
Expand All @@ -41,8 +38,8 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
}

promptImage := promptui.Prompt{
Label: "What docker image would you like to use with this project",
Default: strcase.ToKebab(fmt.Sprintf("organisation/%v", name)),
Label: "What docker image would you like to use with this package",
Default: "nginx",
}
image, err := promptImage.Run()
if err != nil {
Expand All @@ -58,15 +55,6 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
return core.GeneratePackageSpec{}, errors.Wrap(err, "")
}

promptStack := promptui.Prompt{
Label: "Which stack does your package belong to",
Default: "instant",
}
stack, err := promptStack.Run()
if err != nil {
return core.GeneratePackageSpec{}, errors.Wrap(err, "")
}

promptType := promptui.Select{
Label: "What type best suites your package",
Items: []string{"infrastructure", "use-case"},
Expand Down Expand Up @@ -94,17 +82,17 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
includeDevFile = true

promptTargetPort := promptui.Prompt{
Label: "Which port would you like to target in dev mode?",
Default: "8080",
Label: "Which port would you like to target on the container in dev mode?",
Default: "80",
}
targetPort, err = promptTargetPort.Run()
if err != nil {
return core.GeneratePackageSpec{}, errors.Wrap(err, "")
}

promptPublishedPort := promptui.Prompt{
Label: "Which port would you like published in dev mode?",
Default: "8081",
Label: "Which port would you like published on the host in dev mode?",
Default: "8080",
}
publishedPort, err = promptPublishedPort.Run()
if err != nil {
Expand All @@ -117,7 +105,6 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
Name: name,
Image: image,
Description: description,
Stack: stack,
Type: packageType,
IncludeDevFile: includeDevFile,
TargetPort: targetPort,
Expand Down
1 change: 0 additions & 1 deletion cli/src/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ type GeneratePackageSpec struct {
Id string
Name string
Image string
Stack string
Description string
Type string
IncludeDevFile bool
Expand Down
15 changes: 5 additions & 10 deletions cli/src/features/test-package/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ declare ACTION=""
declare MODE=""
declare COMPOSE_FILE_PATH=""
declare UTILS_PATH=""
declare SERVICE_NAMES=()
declare STACK="test-package"

function init_vars() {
ACTION=$1
Expand All @@ -17,15 +17,11 @@ function init_vars() {

UTILS_PATH="${COMPOSE_FILE_PATH}/../utils"

SERVICE_NAMES=(
"test-package"
)

readonly ACTION
readonly MODE
readonly COMPOSE_FILE_PATH
readonly UTILS_PATH
readonly SERVICE_NAMES
readonly STACK
}

# shellcheck disable=SC1091
Expand All @@ -44,16 +40,15 @@ function initialize_package() {
fi

(
docker::deploy_service "${COMPOSE_FILE_PATH}" "$package_dev_compose_filename"
docker::deploy_sanity "${SERVICE_NAMES[@]}"
docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$package_dev_compose_filename"
) || {
log error "Failed to deploy package"
exit 1
}
}

function destroy_package() {
docker::service_destroy "${SERVICE_NAMES[@]}"
docker::stack_destroy $STACK
}

main() {
Expand All @@ -67,7 +62,7 @@ main() {
elif [[ "${ACTION}" == "down" ]]; then
log info "Scaling down package"

docker::scale_services_down "${SERVICE_NAMES[@]}"
docker::scale_services $STACK 0
elif [[ "${ACTION}" == "destroy" ]]; then
log info "Destroying package"

Expand Down
1 change: 0 additions & 1 deletion cli/src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ require (
github.com/cucumber/godog v0.12.5
github.com/docker/cli v20.10.21+incompatible
github.com/docker/docker v20.10.21+incompatible
github.com/iancoleman/strcase v0.2.0
github.com/luno/jettison v0.0.0-20221009180414-a591f4833ce4
github.com/manifoldco/promptui v0.9.0
github.com/spf13/cobra v1.6.1
Expand Down
2 changes: 0 additions & 2 deletions cli/src/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,6 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down

0 comments on commit 966c3f5

Please sign in to comment.