-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f481a20
commit 49e548d
Showing
5 changed files
with
86 additions
and
49 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,30 @@ | ||
# Use the official Golang image to create a build artifact. | ||
# This is based on Debian and sets the GOPATH to /go. | ||
# https://hub.docker.com/_/golang | ||
FROM golang:1.14 as builder | ||
|
||
# Create and change to the app directory. | ||
WORKDIR /app | ||
|
||
# Retrieve application dependencies using go modules. | ||
# Allows container builds to reuse downloaded dependencies. | ||
COPY go.* ./ | ||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
COPY .env ./ | ||
COPY database.env ./ | ||
FROM golang:1.14-alpine | ||
|
||
RUN apk add --no-cache git | ||
|
||
# ENV GO111MODULE=on | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app/GoGinApi | ||
|
||
# We want to populate the module cache based on the go.{mod,sum} files. | ||
COPY go.mod . | ||
COPY go.sum . | ||
COPY .env . | ||
COPY database.env . | ||
|
||
RUN go mod download | ||
|
||
# Copy local code to the container image. | ||
COPY . ./ | ||
COPY . . | ||
|
||
RUN CGO_ENABLED=0 go test -v | ||
|
||
# Build the binary. | ||
# -mod=readonly ensures immutable go.mod and go.sum in container builds. | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server | ||
|
||
# Use the official Alpine image for a lean production container. | ||
# https://hub.docker.com/_/alpine | ||
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | ||
FROM alpine:3 | ||
RUN apk add --no-cache ca-certificates | ||
# Build the Go app | ||
RUN go build -o ./out/GoGinApi . | ||
|
||
# Copy the binary to the production image from the builder stage. | ||
COPY --from=builder /app/server /server | ||
|
||
# This container exposes port 8080 to the outside world | ||
EXPOSE 8082 | ||
|
||
# Run the web service on container startup. | ||
CMD ["/server"] | ||
# Run the binary program produced by `go install` | ||
CMD ["./out/GoGinApi"] |
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,30 +1,41 @@ | ||
FROM golang:1.14-alpine | ||
|
||
RUN apk add --no-cache git | ||
# Use the official Golang image to create a build artifact. | ||
# This is based on Debian and sets the GOPATH to /go. | ||
# https://hub.docker.com/_/golang | ||
FROM golang:1.14 as builder | ||
|
||
# ENV GO111MODULE=on | ||
# Create and change to the app directory. | ||
WORKDIR /app | ||
|
||
# Set the Current Working Directory inside the container | ||
WORKDIR /app/GoGinApi | ||
|
||
# We want to populate the module cache based on the go.{mod,sum} files. | ||
COPY go.mod . | ||
COPY go.sum . | ||
COPY .env . | ||
COPY database.env . | ||
# Retrieve application dependencies using go modules. | ||
# Allows container builds to reuse downloaded dependencies. | ||
COPY go.* ./ | ||
COPY go.mod ./ | ||
COPY go.sum ./ | ||
COPY .env ./ | ||
COPY database.env ./ | ||
|
||
RUN go mod download | ||
|
||
COPY . . | ||
# Copy local code to the container image. | ||
COPY . ./ | ||
|
||
RUN CGO_ENABLED=0 go test -v | ||
|
||
# Build the Go app | ||
RUN go build -o ./out/GoGinApi . | ||
# Build the binary. | ||
# -mod=readonly ensures immutable go.mod and go.sum in container builds. | ||
RUN CGO_ENABLED=0 GOOS=linux go build -mod=readonly -v -o server | ||
|
||
# Use the official Alpine image for a lean production container. | ||
# https://hub.docker.com/_/alpine | ||
# https://docs.docker.com/develop/develop-images/multistage-build/#use-multi-stage-builds | ||
FROM alpine:3 | ||
RUN apk add --no-cache ca-certificates | ||
|
||
# Copy the binary to the production image from the builder stage. | ||
COPY --from=builder /app/server /server | ||
|
||
# This container exposes port 8080 to the outside world | ||
EXPOSE 8082 | ||
|
||
# Run the binary program produced by `go install` | ||
CMD ["./out/GoGinApi"] | ||
# Run the web service on container startup. | ||
CMD ["/server"] |
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
drop table people; | ||
drop table videos; | ||
|
||
create table people | ||
( | ||
id bigserial not null | ||
constraint people_pkey | ||
primary key, | ||
first_name varchar(32), | ||
last_name varchar(32), | ||
age integer, | ||
email varchar(256) | ||
); | ||
|
||
create table videos | ||
( | ||
id bigserial not null | ||
constraint videos_pkey | ||
primary key, | ||
title varchar(100), | ||
description varchar(200), | ||
url varchar(256) | ||
constraint videos_url_key | ||
unique, | ||
person_id bigint, | ||
created_at timestamp with time zone default CURRENT_TIMESTAMP, | ||
updated_at timestamp with time zone default CURRENT_TIMESTAMP | ||
); | ||
|
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