Skip to content

Commit d3c958a

Browse files
committed
chore: add dockerfile
1 parent ba3c331 commit d3c958a

5 files changed

+71
-0
lines changed

.dockerignore

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Add files here to avoid adding them to images when using ADD or COPY
2+
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file
3+
4+
# For example:
5+
# # comment
6+
# */temp*
7+
# */*/temp*
8+
# temp?
9+
10+
.dockerignore
11+
docker-compose.yaml
12+
Dockerfile

Dockerfile

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# syntax=docker/dockerfile:1
2+
3+
FROM golang:1.20-alpine AS development
4+
5+
VOLUME [ "/project" ]
6+
7+
WORKDIR /project
8+
9+
RUN go install github.com/cosmtrek/air@latest
10+
11+
ENTRYPOINT [ "air" ]
12+
13+
FROM golang:1.20-alpine AS builder
14+
15+
WORKDIR /app
16+
17+
COPY go.mod go.sum ./
18+
RUN go mod download
19+
20+
# Copy project files
21+
# NOTE: For more efficient builds, copy only
22+
# required files here.
23+
# For example, for a Go project, you may only
24+
# need go.mod, go.sum and the actual *.go files
25+
# that make up your project
26+
COPY . .
27+
28+
RUN CGO_ENABLED=0 GOOS=linux go build -o go-scaffold
29+
30+
FROM scratch AS production
31+
32+
COPY --from=builder /app/go-scaffold .
33+
34+
ENTRYPOINT [ "/go-scaffold" ]

Taskfile.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
version: 3
22

3+
vars:
4+
VERSION: v0.0.1
5+
36
tasks:
47
test:
58
cmds:
@@ -29,3 +32,15 @@ tasks:
2932
cmds:
3033
- go run . -i testdata/input.json -o testoutput testdata/template
3134
- tree testoutput
35+
36+
docker_build:
37+
cmds:
38+
- docker build . -t forrestloomis786/go-scaffold:latest --target production
39+
- docker build . -t forrestloomis786/go-scaffold:{{.VERSION}} --target production
40+
41+
push:
42+
deps:
43+
- docker_build
44+
cmds:
45+
- docker push forrestloomis786/go-scaffold:latest
46+
- docker push forrestloomis786/go-scaffold:{{.VERSION}}

compose-dev.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
dev-app:
3+
build:
4+
context: ./
5+
target: development
6+
volumes:
7+
- .:/project

docker-compose.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
services:
2+
app:
3+
build: ./

0 commit comments

Comments
 (0)