diff --git a/.circleci/config.yml b/.circleci/config.yml new file mode 100644 index 0000000..a3439da --- /dev/null +++ b/.circleci/config.yml @@ -0,0 +1,37 @@ +# Javascript Node CircleCI 2.0 configuration file +# +# Check https://circleci.com/docs/2.0/language-javascript/ for more details +# +version: 2 +jobs: + build: + docker: + # specify the version you desire here + - image: circleci/node:8.11 + + # Specify service dependencies here if necessary + # CircleCI maintains a library of pre-built images + # documented at https://circleci.com/docs/2.0/circleci-images/ + # - image: circleci/mongo:3.4.4 + + working_directory: ~/repo + + steps: + - checkout + + # Download and cache dependencies + - restore_cache: + keys: + - v1-dependencies-{{ checksum "package.json" }} + # fallback to using the latest cache if no exact match is found + - v1-dependencies- + + - run: yarn install + + - save_cache: + paths: + - node_modules + key: v1-dependencies-{{ checksum "package.json" }} + + # run tests! + - run: yarn test \ No newline at end of file diff --git a/generators/app/templates/go/Dockerfile b/generators/app/templates/go/Dockerfile index c6ed4e4..a980b31 100644 --- a/generators/app/templates/go/Dockerfile +++ b/generators/app/templates/go/Dockerfile @@ -1,4 +1,8 @@ -FROM golang +FROM golang AS build-stage COPY . /go/src/github.com/<%= projectName %> RUN go install github.com/<%= projectName %> -ENTRYPOINT /go/bin/<%= projectName %> + +FROM alpine +WORKDIR /app +COPY --from=build-stage /go/bin/<%= projectName %> /app/ +ENTRYPOINT /app/<%= projectName %> \ No newline at end of file diff --git a/test/golangtests.js b/test/golangtests.js index 50b7210..166d9fd 100644 --- a/test/golangtests.js +++ b/test/golangtests.js @@ -66,7 +66,8 @@ describe('Golang project file creation (Non Web project)', function () { var currentFolder = process.cwd().split(path.sep).pop(); assert.fileContent('Dockerfile.debug', 'COPY . /go/src/github.com/' + currentFolder); assert.fileContent('Dockerfile.debug', 'RUN go install github.com/' + currentFolder); - assert.fileContent('Dockerfile.debug', 'ENTRYPOINT /go/bin/' + currentFolder); + assert.fileContent('Dockerfile.debug', 'COPY --from=build-stage /go/bin/' + currentFolder + ' /app/') + assert.fileContent('Dockerfile.debug', 'ENTRYPOINT /app/' + currentFolder); done(); }); @@ -74,7 +75,8 @@ describe('Golang project file creation (Non Web project)', function () { var currentFolder = process.cwd().split(path.sep).pop(); assert.fileContent('Dockerfile', 'COPY . /go/src/github.com/' + currentFolder); assert.fileContent('Dockerfile', 'RUN go install github.com/' + currentFolder); - assert.fileContent('Dockerfile', 'ENTRYPOINT /go/bin/' + currentFolder); + assert.fileContent('Dockerfile', 'COPY --from=build-stage /go/bin/' + currentFolder + ' /app/') + assert.fileContent('Dockerfile', 'ENTRYPOINT /app/' + currentFolder); done(); }); @@ -155,7 +157,8 @@ describe('Golang project file creation (Web project)', function () { var currentFolder = process.cwd().split(path.sep).pop(); assert.fileContent('Dockerfile.debug', 'COPY . /go/src/github.com/' + currentFolder); assert.fileContent('Dockerfile.debug', 'RUN go install github.com/' + currentFolder); - assert.fileContent('Dockerfile.debug', 'ENTRYPOINT /go/bin/' + currentFolder); + assert.fileContent('Dockerfile.debug', 'COPY --from=build-stage /go/bin/' + currentFolder + ' /app/') + assert.fileContent('Dockerfile.debug', 'ENTRYPOINT /app/' + currentFolder); done(); }); @@ -163,7 +166,8 @@ describe('Golang project file creation (Web project)', function () { var currentFolder = process.cwd().split(path.sep).pop(); assert.fileContent('Dockerfile', 'COPY . /go/src/github.com/' + currentFolder); assert.fileContent('Dockerfile', 'RUN go install github.com/' + currentFolder); - assert.fileContent('Dockerfile', 'ENTRYPOINT /go/bin/' + currentFolder); + assert.fileContent('Dockerfile', 'COPY --from=build-stage /go/bin/' + currentFolder + ' /app/') + assert.fileContent('Dockerfile', 'ENTRYPOINT /app/' + currentFolder); done(); });