From df8f1a76b4dfccfaf651996c36c270ab60cd67db Mon Sep 17 00:00:00 2001
From: Ivan Ivanov <ivanivanov@Ivans-MacBook-Air.local>
Date: Tue, 30 Mar 2021 21:29:45 +0100
Subject: [PATCH] Containerisation of the API works.

---
 Dockerfile          | 32 ++++++++++++++++++++++++++++----
 docker-compose.yaml | 10 ++++++++++
 2 files changed, 38 insertions(+), 4 deletions(-)

diff --git a/Dockerfile b/Dockerfile
index 0310e9f..7c95a37 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 e69de29..55644d5 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
-- 
GitLab