generator-reshow 0.16.1 → 0.16.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ # `docker`
2
+
3
+ > TODO: description
4
+
5
+ ## Usage
6
+
7
+ ```
8
+ npx yonpx docker
9
+ ```
@@ -0,0 +1,45 @@
1
+ /**
2
+ * https://yeoman.io/authoring/testing.html
3
+ * https://gilsondev.gitbooks.io/yeoman-authoring/content/authoring/unit_testing.html
4
+ *
5
+ * https://github.com/yeoman/yeoman-assert/blob/main/index.js
6
+ * https://github.com/yeoman/yeoman-test/blob/main/lib/run-context.js
7
+ */
8
+
9
+ const getYoUnit = require("yo-unit");
10
+ const { YoTest, assert } = getYoUnit();
11
+
12
+ describe("!! docker !!", () => {
13
+ let runResult;
14
+
15
+ before(async () => {
16
+ runResult = await YoTest({
17
+ source: __dirname + "/../.",
18
+ params: {
19
+ isReady: true,
20
+ appNamee: "foo",
21
+ description: "foo-desc",
22
+ keyword: "foo-keyword",
23
+ },
24
+ });
25
+ });
26
+
27
+ after(() => {
28
+ if (runResult) {
29
+ runResult.restore();
30
+ }
31
+ });
32
+
33
+ it("should have folder", () => {
34
+ // assert.file(["src", "ui"]);
35
+ });
36
+
37
+ it("should have file", () => {
38
+ // assert.file(["compile.sh", "index.html"]);
39
+ });
40
+
41
+ it("should have content", () => {
42
+ // assert.fileContent('composer.json', 'foo-desc');
43
+ // assert.fileContent('.circleci/config.yml', 'foo');
44
+ });
45
+ });
@@ -0,0 +1,84 @@
1
+ const getYo = require("yo-reshow");
2
+ const { YoGenerator, YoHelper, commonPrompt } = getYo();
3
+
4
+ /**
5
+ * docker Generator
6
+ */
7
+ module.exports = class extends YoGenerator {
8
+ /**
9
+ * Run loop (Life cycle)
10
+ * https://yeoman.io/authoring/running-context.html#the-run-loop
11
+ *
12
+ * 1. initializing
13
+ * 2. prompting
14
+ * 3. configuring
15
+ * 4. default
16
+ * 5. writing
17
+ * 6. conflicts
18
+ * 7. install
19
+ * 8. end
20
+ */
21
+
22
+ /**
23
+ * Questions.
24
+ *
25
+ * https://www.alwaystwisted.com/post.php?s=using-lists-in-a-yeoman-generator
26
+ * https://github.com/SBoudrias/Inquirer.js
27
+ */
28
+ async prompting() {
29
+ const {
30
+ say,
31
+ handleAnswers,
32
+ mergePromptOrOption,
33
+ promptChainLocator,
34
+ promptChain,
35
+ } = YoHelper(this);
36
+
37
+ const prompts = [
38
+ ...commonPrompt.mainName(this),
39
+ ...commonPrompt.desc(this),
40
+ {
41
+ type: "input",
42
+ name: "folderPrefix",
43
+ message: "Please input your folder-prefix?",
44
+ default: "",
45
+ },
46
+ /*
47
+ {
48
+ type: "input",
49
+ name: "xxx",
50
+ message: "Please input xxx?",
51
+ default: "",
52
+ },
53
+ */
54
+ ];
55
+
56
+ const answers = await mergePromptOrOption(prompts, (nextPrompts) =>
57
+ promptChain(promptChainLocator(nextPrompts))
58
+ );
59
+ handleAnswers(answers);
60
+ }
61
+
62
+ writing() {
63
+ this.payload.folderPrefixGitIgnore = this.payload.folderPrefix
64
+ ? this.payload.folderPrefix + "*"
65
+ : "";
66
+
67
+ this.env.options.nodePackageManager = "yarn";
68
+ const { cp, chMainName } = YoHelper(this);
69
+
70
+ // handle change to new folder
71
+ chMainName();
72
+
73
+ // handle copy file
74
+ cp(".env.build", null, this.payload);
75
+ cp("Dockerfile", null, this.payload);
76
+ cp("README.md", null, this.payload);
77
+ cp("_circleci", ".circleci", this.payload);
78
+ cp("_gitignore", ".gitignore", this.payload);
79
+ cp("build.sh", null, this.payload);
80
+ cp("compile.sh", null, this.payload);
81
+ cp("install-packages.sh", null, this.payload);
82
+ cp("support", null, this.payload);
83
+ }
84
+ };
@@ -0,0 +1,4 @@
1
+ sourceImage=<%= mainName %>
2
+ targetImage=<%= mainName %>
3
+ VERSION=0.0
4
+ FOLDER_PREFIX=<%= folderPrefix %>
@@ -0,0 +1,9 @@
1
+ ARG VERSION=${VERSION:-[VERSION]}
2
+
3
+ FROM alpine:3.15
4
+
5
+ # apk
6
+ COPY ./install-packages.sh /usr/local/bin/
7
+ RUN apk update && apk add bash bc \
8
+ && INSTALL_VERSION=$VERSION install-packages.sh \
9
+ && rm /usr/local/bin/install-packages.sh;
@@ -0,0 +1,9 @@
1
+ # `<%= mainName %>`
2
+
3
+ > <%= description %>
4
+
5
+ ## Usage
6
+
7
+ ```
8
+
9
+ ```
@@ -0,0 +1,53 @@
1
+ version: 2.1
2
+
3
+ executors:
4
+ docker-publisher:
5
+ environment:
6
+ IMAGE_NAME: <%= mainName %>
7
+ docker:
8
+ - image: circleci/buildpack-deps:18.04
9
+
10
+ jobs:
11
+ build-and-publish:
12
+ parameters:
13
+ docker-tag:
14
+ type: string
15
+ folder-prefix:
16
+ type: string
17
+ default: "<%= folderPrefix %>"
18
+ executor: docker-publisher
19
+ steps:
20
+ - checkout
21
+ - setup_remote_docker:
22
+ version: 20.10.7
23
+ docker_layer_caching: true
24
+ - run:
25
+ name: Log time
26
+ command: date
27
+ - run:
28
+ name: Gen Docker file
29
+ command: |
30
+ ./build.sh << parameters.docker-tag >>
31
+ ls -la << parameters.folder-prefix >><< parameters.docker-tag >>
32
+ - run:
33
+ name: build Docker image
34
+ command: |
35
+ VERSION=$(support/VERSION.sh)
36
+ BUILD_VERSION=<< parameters.docker-tag >>
37
+ BUILD_FOLDER=<< parameters.folder-prefix >><< parameters.docker-tag >>
38
+ BUILD_ARG=""
39
+ docker build ${BUILD_ARG} -f ${BUILD_FOLDER}/Dockerfile \
40
+ -t $IMAGE_NAME:${BUILD_VERSION} \
41
+ ./${BUILD_FOLDER}
42
+ - run:
43
+ name: Publish Docker Image to Docker Hub
44
+ command: |
45
+ ./compile.sh p << parameters.docker-tag >>
46
+
47
+ workflows:
48
+ run-job:
49
+ jobs:
50
+ - build-and-publish:
51
+ matrix:
52
+ parameters:
53
+ docker-tag: ["0.0"]
@@ -0,0 +1,3 @@
1
+ archive.tar
2
+ .*.sw?
3
+ <%= folderPrefixGitIgnore %>
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DIR="$(
4
+ cd "$(dirname "$0")"
5
+ pwd -P
6
+ )"
7
+
8
+ FOLDER_PREFIX=$(${DIR}/support/FOLDER_PREFIX.sh)
9
+
10
+ do_build() {
11
+ SED_REPLACE_VER=$1
12
+ DEST_FOLDER=${DIR}/${FOLDER_PREFIX}${SED_REPLACE_VER}
13
+ mkdir -p ${DEST_FOLDER}
14
+ echo "building --- Version: " $SED_REPLACE_VER "-->"
15
+ DEST_FILE=${DEST_FOLDER}/Dockerfile
16
+ cp Dockerfile ${DEST_FILE}
17
+ cp install-packages.sh ${DEST_FOLDER}
18
+ sed -i -e "s|\[VERSION\]|$SED_REPLACE_VER|g" ${DEST_FILE}
19
+ if [ -e "${DEST_FILE}-e" ]; then rm ${DEST_FILE}-e; fi
20
+ }
21
+
22
+ do_build $1
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DIR="$(
4
+ cd "$(dirname "$0")"
5
+ pwd -P
6
+ )"
7
+ sourceImage=$(${DIR}/support/sourceImage.sh)
8
+ targetImage=$(${DIR}/support/targetImage.sh)
9
+ archiveFile=$DIR/archive.tar
10
+ VERSION=$(${DIR}/support/VERSION.sh)
11
+ DOCKER_FILE=${DOCKER_FILE:-Dockerfile}
12
+
13
+ list() {
14
+ docker images | head -10
15
+ }
16
+
17
+ tag() {
18
+ tag=$1
19
+ if [ -z "$tag" ]; then
20
+ if [ -z "$VERSION" ]; then
21
+ tag=latest
22
+ else
23
+ tag=$VERSION
24
+ fi
25
+ fi
26
+ echo "* <!-- Start to tag: ${tag}"
27
+ echo $tag
28
+ docker tag $sourceImage ${targetImage}:$tag
29
+ list
30
+ echo "* Finish tag -->"
31
+ }
32
+
33
+ push() {
34
+ PUSH_VERSION=${1:-$VERSION}
35
+ LATEST_TAG=${2:-latest}
36
+ if [ -z "$PUSH_VERSION" ]; then
37
+ tag=latest
38
+ else
39
+ tag=$PUSH_VERSION
40
+ if [ "x$LATEST_TAG" != "xlatest" ]; then
41
+ tag=$LATEST_TAG-$PUSH_VERSION
42
+ fi
43
+ fi
44
+ echo "* <!-- Start to push ${targetImage}:$tag"
45
+ echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_LOGIN" --password-stdin
46
+ docker push ${targetImage}:$tag
47
+ echo "* Finish to push -->"
48
+ echo ""
49
+ if [ ! -z "$1" ]; then
50
+ if [ "x$VERSION" == "x$PUSH_VERSION" ]; then
51
+ echo "* <!-- Start to auto push ${targetImage}:${LATEST_TAG}"
52
+ docker tag ${targetImage}:$tag ${targetImage}:${LATEST_TAG}
53
+ docker push ${targetImage}:${LATEST_TAG}
54
+ echo "* Finish to push -->"
55
+ fi
56
+ fi
57
+ }
58
+
59
+ build() {
60
+ if [ -z "$1" ]; then
61
+ NO_CACHE=""
62
+ else
63
+ NO_CACHE="--no-cache"
64
+ fi
65
+ BUILD_ARG=""
66
+ if [ ! -z "$VERSION" ]; then
67
+ BUILD_ARG="$BUILD_ARG --build-arg VERSION=${VERSION}"
68
+ fi
69
+ echo build: ${DIR}/${DOCKER_FILE}
70
+ if [ -z "$NO_CACHE" ]; then
71
+ echo nocache: ${NO_CACHE}
72
+ fi
73
+ docker build ${BUILD_ARG} ${NO_CACHE} -f ${DIR}/${DOCKER_FILE} -t $sourceImage ${DIR}
74
+ list
75
+ }
76
+
77
+ save() {
78
+ echo save
79
+ docker save $sourceImage > $archiveFile
80
+ }
81
+
82
+ restore() {
83
+ echo restore
84
+ docker save --output $archiveFile $sourceImage
85
+ }
86
+
87
+ case "$1" in
88
+ save)
89
+ save
90
+ ;;
91
+ restore)
92
+ restore
93
+ ;;
94
+ p)
95
+ push $2 $3
96
+ ;;
97
+ t)
98
+ tag $2
99
+ ;;
100
+ nocache)
101
+ build --no-cache
102
+ ;;
103
+ auto)
104
+ build
105
+ tag
106
+ ;;
107
+ b)
108
+ build
109
+ ;;
110
+ l)
111
+ list
112
+ ;;
113
+ *)
114
+ echo "$0 [save|restore|p|t|nocache|auto|b|l]"
115
+ exit
116
+ ;;
117
+ esac
118
+
119
+ exit $?
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env bash
2
+
3
+ DIR="$(
4
+ cd "$(dirname "$0")"
5
+ pwd -P
6
+ )"
7
+ VERSION=${VERSION:-latest}
8
+ SOURCE_IMAGE=$(${DIR}/support/sourceImage.sh)
9
+
10
+ C=''
11
+ for i in "$@"; do
12
+ i="${i//\\/\\\\}"
13
+ C="$C \"${i//\"/\\\"}\""
14
+ done
15
+
16
+ pid=$$
17
+
18
+ cli='env docker run --rm -it'
19
+ cli+=" -v $DIR:$DIR"
20
+ cli+=" -w $DIR"
21
+ cli+=" --name ${SOURCE_IMAGE}-${pid} ${SOURCE_IMAGE}:${VERSION}"
22
+ cli+=" sh ${C}"
23
+
24
+ bash -c "$cli"
@@ -0,0 +1,24 @@
1
+ #!/bin/bash
2
+
3
+ INSTALL=""
4
+
5
+ BUILD_DEPS=""
6
+
7
+ echo "###"
8
+ echo "# Will install"
9
+ echo "###"
10
+ echo ""
11
+ echo $INSTALL
12
+ echo ""
13
+ echo "###"
14
+ echo "# Will build package"
15
+ echo "###"
16
+ echo ""
17
+ echo $BUILD_DEPS
18
+ echo ""
19
+
20
+ apk add --virtual .build-deps $BUILD_DEPS && apk add $INSTALL
21
+
22
+ apk del -f .build-deps && rm -rf /var/cache/apk/* || exit 1
23
+
24
+ exit 0
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ DIR="$( cd "$(dirname "$0")" ; pwd -P )"
3
+
4
+ if [ -z $FOLDER_PREFIX ]; then
5
+ FOLDER_PREFIX=$(awk -F "=" '/^FOLDER_PREFIX/ {print $2}' ${DIR}/../.env.build)
6
+ fi
7
+
8
+ echo $FOLDER_PREFIX
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ DIR="$( cd "$(dirname "$0")" ; pwd -P )"
3
+
4
+ if [ -z $VERSION ]; then
5
+ VERSION=$(awk -F "=" '/^VERSION/ {print $2}' ${DIR}/../.env.build)
6
+ fi
7
+
8
+ echo $VERSION
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ DIR="$( cd "$(dirname "$0")" ; pwd -P )"
3
+
4
+ if [ -z $sourceImage ]; then
5
+ sourceImage=$(awk -F "=" '/^sourceImage/ {print $2}' ${DIR}/../.env.build)
6
+ fi
7
+
8
+ echo $sourceImage
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ DIR="$( cd "$(dirname "$0")" ; pwd -P )"
3
+
4
+ if [ -z $targetImage ]; then
5
+ targetImage=$(awk -F "=" '/^targetImage/ {print $2}' ${DIR}/../.env.build)
6
+ fi
7
+
8
+ echo $targetImage
@@ -50,7 +50,7 @@ module.exports = class extends YoGenerator {
50
50
  const answers = await mergePromptOrOption(prompts, (nextPrompts) =>
51
51
  promptChain(promptChainLocator(nextPrompts))
52
52
  );
53
- handleAnswers(answers, payload => { say(payload) });
53
+ handleAnswers(answers);
54
54
  }
55
55
 
56
56
  writing() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "generator-reshow",
3
- "version": "0.16.1",
3
+ "version": "0.16.2",
4
4
  "description": "Yeoman generator for reshow. (app, generator, ...etc)",
5
5
  "author": "Hill <hill@kimo.com>",
6
6
  "repository": {