build: optimize
This commit is contained in:
parent
415b01cb1e
commit
cc79aefe9b
@ -1,9 +1,9 @@
|
||||
GRPC_HOST=0.0.0.0
|
||||
GPRC_PORT=9001
|
||||
GPRC_PORT=9000
|
||||
|
||||
HTTP_PORT=8001
|
||||
HTTP_PORT=8000
|
||||
|
||||
MONGO_HOST=mongo
|
||||
MONGO_HOST=discount-db
|
||||
MONGO_PORT=27017
|
||||
MONGO_USER=test
|
||||
MONGO_PASSWORD=test
|
||||
|
59
Dockerfile
59
Dockerfile
@ -1,71 +1,54 @@
|
||||
# BUILD
|
||||
FROM golang:1.19.5-alpine AS build
|
||||
FROM golang:1.20.3-alpine AS build
|
||||
|
||||
# Update depences
|
||||
RUN apk update && apk add --no-cache curl
|
||||
# Create build directory
|
||||
RUN mkdir /app/bin -p
|
||||
RUN mkdir /bin/golang-migrate -p
|
||||
# Download migrate app
|
||||
RUN GOLANG_MIGRATE_VERSION=v4.15.1 && \
|
||||
curl -L https://github.com/golang-migrate/migrate/releases/download/${GOLANG_MIGRATE_VERSION}/migrate.linux-amd64.tar.gz |\
|
||||
tar xvz migrate -C /bin/golang-migrate
|
||||
# Download health check utility
|
||||
RUN GRPC_HEALTH_PROBE_VERSION=v0.4.6 && \
|
||||
wget -qO/bin/grpc_health_probe https://github.com/grpc-ecosystem/grpc-health-probe/releases/download/${GRPC_HEALTH_PROBE_VERSION}/grpc_health_probe-linux-amd64 && \
|
||||
chmod +x /bin/grpc_health_probe
|
||||
# Set home directory
|
||||
# Update packages and clear cache
|
||||
RUN apk update && apk add --no-cache curl && rm -rf /var/cache/apk/*
|
||||
# Set work directory
|
||||
WORKDIR /app
|
||||
# Copy go.mod
|
||||
ADD go.mod go.sum /app/
|
||||
# Create binary directory
|
||||
RUN mkdir /app/bin -p
|
||||
# Create golang migrate util directory
|
||||
RUN mkdir /bin/golang-migrate -p
|
||||
# Add migrate tool
|
||||
ADD ./tools/migrate /bin/golang-migrate/
|
||||
# Add main files to app
|
||||
ADD . .
|
||||
# Download go depences
|
||||
RUN go mod download
|
||||
# Copy all local files
|
||||
ADD . /app
|
||||
# Build app
|
||||
RUN GOOS=linux go build -o bin ./...
|
||||
|
||||
|
||||
|
||||
# TEST
|
||||
FROM alpine:latest AS test
|
||||
FROM alpine:3.18.3 AS test
|
||||
|
||||
# Install packages
|
||||
RUN apk --no-cache add ca-certificates
|
||||
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
|
||||
# Set GO111MODULE env
|
||||
ENV GO111MODULE=off
|
||||
# Create home directory
|
||||
WORKDIR /app
|
||||
# Copy build file
|
||||
COPY --from=build /app/bin/app ./app
|
||||
# CMD
|
||||
CMD ["./app"]
|
||||
|
||||
|
||||
|
||||
# MIGRATION
|
||||
FROM alpine:latest AS migration
|
||||
|
||||
# Install packages
|
||||
RUN apk --no-cache add ca-certificates
|
||||
# Create home directory
|
||||
WORKDIR /app
|
||||
# Copy migration dir
|
||||
COPY --from=build /app/migrations/tests ./migrations
|
||||
COPY --from=build /app/migrations/test ./migrations
|
||||
# Install migrate tool
|
||||
COPY --from=build /bin/golang-migrate /usr/local/bin
|
||||
# CMD
|
||||
CMD [ "./app" ]
|
||||
|
||||
|
||||
|
||||
# PRODUCTION
|
||||
FROM alpine:latest AS production
|
||||
FROM alpine:3.18.3 AS production
|
||||
|
||||
# Install packages
|
||||
RUN apk --no-cache add ca-certificates
|
||||
RUN apk --no-cache add ca-certificates && rm -rf /var/cache/apk/*
|
||||
# Create home directory
|
||||
WORKDIR /app
|
||||
# Copy build file
|
||||
COPY --from=build /app/bin/app ./app
|
||||
# Copy grpc health probe dir
|
||||
COPY --from=build /bin/grpc_health_probe /bin/grpc_health_probe
|
||||
# Install migrate tool
|
||||
COPY --from=build /bin/golang-migrate /usr/local/bin
|
||||
# CMD
|
||||
|
@ -1,46 +1,51 @@
|
||||
version: "3"
|
||||
|
||||
services:
|
||||
app:
|
||||
discount-service:
|
||||
container_name: discount-service
|
||||
build:
|
||||
context: ../../.
|
||||
dockerfile: Dockerfile
|
||||
target: test
|
||||
env_file:
|
||||
- ../../.env.test
|
||||
ports:
|
||||
- 9001:9001
|
||||
- 8001:8001
|
||||
depends_on:
|
||||
- migration
|
||||
- discount-db
|
||||
- discount-migration
|
||||
ports:
|
||||
- 9040:9000
|
||||
- 8008:8000
|
||||
networks:
|
||||
- integration_test
|
||||
- test
|
||||
|
||||
migration:
|
||||
discount-migration:
|
||||
container_name: discount-migration
|
||||
build:
|
||||
context: ../../.
|
||||
dockerfile: Dockerfile
|
||||
target: migration
|
||||
target: test
|
||||
command:
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
'migrate -source file://migrations -database "mongodb://$MONGO_USER:$MONGO_PASSWORD@$MONGO_HOST:$MONGO_PORT/$MONGO_AUTH?authSource=$MONGO_AUTH" up',
|
||||
'migrate -source file://migrations -database "mongodb://test:test@discount-db:27017/admin?authSource=admin" up',
|
||||
]
|
||||
depends_on:
|
||||
- mongo
|
||||
- discount-db
|
||||
networks:
|
||||
- integration_test
|
||||
- test
|
||||
|
||||
mongo:
|
||||
image: 'mongo:6.0.3'
|
||||
discount-db:
|
||||
container_name: discount-db
|
||||
image: "mongo:6.0.3"
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: test
|
||||
MONGO_INITDB_ROOT_PASSWORD: test
|
||||
ports:
|
||||
- '27017:27017'
|
||||
- "27023:27017"
|
||||
networks:
|
||||
- integration_test
|
||||
- test
|
||||
|
||||
|
||||
networks:
|
||||
integration_test:
|
||||
test:
|
1029
template.json
1029
template.json
File diff suppressed because it is too large
Load Diff
BIN
tools/migrate
Normal file
BIN
tools/migrate
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user