Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

golang Dockerfile now using multistage build #145

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions generators/app/templates/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 %>
12 changes: 8 additions & 4 deletions test/golangtests.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,17 @@ 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();
});

it('correct dockerfile contents (release)', function (done) {
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();
});

Expand Down Expand Up @@ -155,15 +157,17 @@ 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();
});

it('correct dockerfile contents (release)', function (done) {
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();
});

Expand Down