Skip to content

Commit 966c3f5

Browse files
authored
Merge pull request #72 from openhie/package-generate-update
Update and fix package generate command
2 parents 7e4c274 + 1f480de commit 966c3f5

File tree

9 files changed

+22
-50
lines changed

9 files changed

+22
-50
lines changed

cli/src/cmd/pkg/generate.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"os"
66
"path"
7-
"path/filepath"
87

98
"cli/core/generate"
109
"cli/core/prompt"
@@ -27,13 +26,14 @@ func packageGenerateCommand() *cobra.Command {
2726
panic(err)
2827
}
2928

30-
ex, err := os.Executable()
29+
// Get the current working directory
30+
cwd, err := os.Getwd()
3131
if err != nil {
3232
log.Error(ctx, err)
3333
panic(err)
3434
}
3535

36-
packagePath := path.Join(filepath.Dir(ex), resp.Id)
36+
packagePath := path.Join(cwd, resp.Id)
3737
err = os.Mkdir(packagePath, os.ModePerm)
3838
if err != nil {
3939
log.Error(ctx, err)

cli/src/cmd/version/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.3.2
1+
2.4.0

cli/src/core/generate/generate_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func Test_createFileFromTemplate(t *testing.T) {
2828
generatePackSpec := core.GeneratePackageSpec{
2929
Id: "test-package",
3030
Name: "Test Package",
31-
Stack: "test-stack",
3231
Image: "test/image",
3332
Description: "A package for testing",
3433
Type: "infrastructure",

cli/src/core/generate/template/package/swarm.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare ACTION=""
44
declare MODE=""
55
declare COMPOSE_FILE_PATH=""
66
declare UTILS_PATH=""
7-
declare SERVICE_NAMES=()
7+
declare STACK="{{.Id}}"
88

99
function init_vars() {
1010
ACTION=$1
@@ -17,15 +17,11 @@ function init_vars() {
1717

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

20-
SERVICE_NAMES=(
21-
"{{.Id}}"
22-
)
23-
2420
readonly ACTION
2521
readonly MODE
2622
readonly COMPOSE_FILE_PATH
2723
readonly UTILS_PATH
28-
readonly SERVICE_NAMES
24+
readonly STACK
2925
}
3026

3127
# shellcheck disable=SC1091
@@ -44,16 +40,15 @@ function initialize_package() {
4440
fi
4541

4642
(
47-
docker::deploy_service "${COMPOSE_FILE_PATH}" "$package_dev_compose_filename"
48-
docker::deploy_sanity "${SERVICE_NAMES[@]}"
43+
docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$package_dev_compose_filename"
4944
) || {
5045
log error "Failed to deploy package"
5146
exit 1
5247
}
5348
}
5449

5550
function destroy_package() {
56-
docker::service_destroy "${SERVICE_NAMES[@]}"
51+
docker::stack_destroy $STACK
5752
}
5853

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

70-
docker::scale_services_down "${SERVICE_NAMES[@]}"
65+
docker::scale_services $STACK 0
7166
elif [[ "${ACTION}" == "destroy" ]]; then
7267
log info "Destroying package"
7368

cli/src/core/prompt/package.go

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package prompt
22

33
import (
44
"cli/core"
5-
"fmt"
65

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

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

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

61-
promptStack := promptui.Prompt{
62-
Label: "Which stack does your package belong to",
63-
Default: "instant",
64-
}
65-
stack, err := promptStack.Run()
66-
if err != nil {
67-
return core.GeneratePackageSpec{}, errors.Wrap(err, "")
68-
}
69-
7058
promptType := promptui.Select{
7159
Label: "What type best suites your package",
7260
Items: []string{"infrastructure", "use-case"},
@@ -94,17 +82,17 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
9482
includeDevFile = true
9583

9684
promptTargetPort := promptui.Prompt{
97-
Label: "Which port would you like to target in dev mode?",
98-
Default: "8080",
85+
Label: "Which port would you like to target on the container in dev mode?",
86+
Default: "80",
9987
}
10088
targetPort, err = promptTargetPort.Run()
10189
if err != nil {
10290
return core.GeneratePackageSpec{}, errors.Wrap(err, "")
10391
}
10492

10593
promptPublishedPort := promptui.Prompt{
106-
Label: "Which port would you like published in dev mode?",
107-
Default: "8081",
94+
Label: "Which port would you like published on the host in dev mode?",
95+
Default: "8080",
10896
}
10997
publishedPort, err = promptPublishedPort.Run()
11098
if err != nil {
@@ -117,7 +105,6 @@ func GeneratePackagePrompt() (core.GeneratePackageSpec, error) {
117105
Name: name,
118106
Image: image,
119107
Description: description,
120-
Stack: stack,
121108
Type: packageType,
122109
IncludeDevFile: includeDevFile,
123110
TargetPort: targetPort,

cli/src/core/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type GeneratePackageSpec struct {
3939
Id string
4040
Name string
4141
Image string
42-
Stack string
4342
Description string
4443
Type string
4544
IncludeDevFile bool

cli/src/features/test-package/swarm.sh

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ declare ACTION=""
44
declare MODE=""
55
declare COMPOSE_FILE_PATH=""
66
declare UTILS_PATH=""
7-
declare SERVICE_NAMES=()
7+
declare STACK="test-package"
88

99
function init_vars() {
1010
ACTION=$1
@@ -17,15 +17,11 @@ function init_vars() {
1717

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

20-
SERVICE_NAMES=(
21-
"test-package"
22-
)
23-
2420
readonly ACTION
2521
readonly MODE
2622
readonly COMPOSE_FILE_PATH
2723
readonly UTILS_PATH
28-
readonly SERVICE_NAMES
24+
readonly STACK
2925
}
3026

3127
# shellcheck disable=SC1091
@@ -44,16 +40,15 @@ function initialize_package() {
4440
fi
4541

4642
(
47-
docker::deploy_service "${COMPOSE_FILE_PATH}" "$package_dev_compose_filename"
48-
docker::deploy_sanity "${SERVICE_NAMES[@]}"
43+
docker::deploy_service $STACK "${COMPOSE_FILE_PATH}" "docker-compose.yml" "$package_dev_compose_filename"
4944
) || {
5045
log error "Failed to deploy package"
5146
exit 1
5247
}
5348
}
5449

5550
function destroy_package() {
56-
docker::service_destroy "${SERVICE_NAMES[@]}"
51+
docker::stack_destroy $STACK
5752
}
5853

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

70-
docker::scale_services_down "${SERVICE_NAMES[@]}"
65+
docker::scale_services $STACK 0
7166
elif [[ "${ACTION}" == "destroy" ]]; then
7267
log info "Destroying package"
7368

cli/src/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/cucumber/godog v0.12.5
77
github.com/docker/cli v20.10.21+incompatible
88
github.com/docker/docker v20.10.21+incompatible
9-
github.com/iancoleman/strcase v0.2.0
109
github.com/luno/jettison v0.0.0-20221009180414-a591f4833ce4
1110
github.com/manifoldco/promptui v0.9.0
1211
github.com/spf13/cobra v1.6.1

cli/src/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
503503
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
504504
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
505505
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
506-
github.com/iancoleman/strcase v0.2.0 h1:05I4QRnGpI0m37iZQRuskXh+w77mr6Z41lwQzuHLwW0=
507-
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
508506
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
509507
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
510508
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=

0 commit comments

Comments
 (0)