-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from kpirnie/main
Fix Dockerfile for Local Go Test with Redis
- Loading branch information
Showing
4 changed files
with
42 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,42 @@ | ||
# Start from the official Golang image | ||
FROM golang:alpine AS build | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed | ||
RUN go mod download | ||
|
||
# Copy the source code from the current directory to the Working Directory inside the container | ||
COPY . . | ||
|
||
RUN go test ./... \ | ||
&& go build -ldflags='-s -w' -o main . | ||
|
||
# End from the latest alpine image | ||
# hadolint ignore=DL3007 | ||
FROM alpine:latest | ||
|
||
# add bash and timezone data | ||
# hadolint ignore=DL3018 | ||
RUN apk --no-cache add tzdata | ||
|
||
# set the current workdir | ||
WORKDIR /app | ||
|
||
# copy in our compiled GO app | ||
COPY --from=build /app/main /app/ | ||
|
||
# the containers entrypoint | ||
ENTRYPOINT [ "/app/main" ] | ||
# Start from the official Golang image | ||
FROM golang:alpine AS build | ||
|
||
# install redis | ||
# hadolint ignore=DL3018 | ||
RUN apk --no-cache add redis && \ | ||
sed -i "s/bind .*/bind 127.0.0.1/g" /etc/redis.conf | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app | ||
|
||
# Copy go mod and sum files | ||
COPY go.mod go.sum ./ | ||
|
||
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed | ||
RUN go mod download | ||
|
||
# Copy the source code from the current directory to the Working Directory inside the container | ||
COPY . . | ||
|
||
# fire up redis server and test and build the app. | ||
RUN \ | ||
redis-server --daemonize yes && \ | ||
go test ./... \ | ||
&& go build -ldflags='-s -w' -o main . | ||
|
||
# End from the latest alpine image | ||
# hadolint ignore=DL3007 | ||
FROM alpine:latest | ||
|
||
# add bash and timezone data | ||
# hadolint ignore=DL3018 | ||
RUN apk --no-cache add tzdata | ||
|
||
# set the current workdir | ||
WORKDIR /app | ||
|
||
# copy in our compiled GO app | ||
COPY --from=build /app/main /app/ | ||
|
||
# the containers entrypoint | ||
ENTRYPOINT [ "/app/main" ] |