diff --git a/Dockerfile b/Dockerfile index 0310e9fbba9d3c113a2a53916c09b450a5cf2ac7..7c95a3710a1086db7f2ee5bcd99724fbd21f2e14 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,29 @@ -FROM golang:1.16.2-buster -WORKDIR . +# Start from golang base image +FROM golang:alpine + +# The latest alpine images don't have some tools like (`git` and `bash`). +# Adding git, bash and openssh to the image +RUN apk update && apk upgrade && \ + apk add --no-cache bash git openssh build-base + +# 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 the go.sum files are not changed +RUN go mod download + +# Copy the source from the current directory to the working Directory inside the container COPY . . -RUN make build -RUN make build file=example.json \ No newline at end of file + +# Build the Go app +RUN go build + +# Expose port 8080 to the outside world +EXPOSE 8080 + +RUN chmod +x /app/json-utility +#Command to run the executable +CMD ["./json-utility", "CONTAINER"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..55644d59cb41af23f07cf6b4d32ab678f59d322d 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -0,0 +1,10 @@ +version: "3" +services: + app: + container_name: rest-api-json + build: . + restart: on-failure + volumes: + - .:/usr/src/app/ + ports: + - 8080:8080