-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker.go
More file actions
62 lines (45 loc) · 1.27 KB
/
docker.go
File metadata and controls
62 lines (45 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import "strings"
const dockerFileContent = `## Generic Go dockerfile
# Stage: build
# https://hub.docker.com/_/golang
FROM golang:alpine AS buildStage
ENV GOBIN=/go/bin
WORKDIR /go/src
COPY ./ ./
RUN go install -mod=vendor ./...
# Stage: final
FROM alpine:latest AS final
RUN apk add \
curl
COPY --from=buildStage /go/bin/* /usr/local/bin/
WORKDIR /usr/local/bin
# Sets command to run the first executable in the current dir. This will be the just built golang binary
CMD find ./ -maxdepth 1 -perm -111 -type f -exec {} \;
`
const dockerComposeFileContent = `## Generic docker-compose
version: "3"
services:
main:
environment:
ENV_VAR1: 'NOT_SET'
ENV_VAR2: 'NOT_SET'
build:
context: .
command: |-
<project_name>
image: <project_name>
ports:
- "8080:8080"
`
// writeDocker writes a Dockerfile to the project output dir from
// const dockerFileContent
func writeDocker(project, projectPath *string) {
var b []byte
// create Dockerfile from const
b = []byte(dockerFileContent)
writeFile(project, projectPath, "Dockerfile", b)
// create docker-compose from const
b = []byte(strings.Replace(dockerComposeFileContent, "<project_name>", *project, -1))
writeFile(project, projectPath, "docker-compose.yaml", b)
}