Skip to content

Commit 7400b9b

Browse files
committed
Docker file for the rest api
1 parent ca3a743 commit 7400b9b

File tree

7 files changed

+25
-12
lines changed

7 files changed

+25
-12
lines changed

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM golang:latest AS buildContainer
2+
WORKDIR /go/src/app
3+
COPY . .
4+
#flags: -s -w to remove symbol table and debug info
5+
#CGO_ENALBED=0 is required for the code to run properly when copied alpine
6+
RUN CGO_ENABLED=0 GOOS=linux go build -v -mod mod -ldflags "-s -w" -o restapi ./app
7+
8+
FROM alpine:latest
9+
WORKDIR /app
10+
COPY --from=buildContainer /go/src/app/restapi .
11+
12+
ENV DBUSER root
13+
ENV DBPASSWORD jobs@123
14+
ENV DBNAME api
15+
ENV DBHOST localhost
16+
ENV DBPORT 3306
17+
18+
EXPOSE 8080
19+
20+
CMD ["./restapi"]

api_test.go renamed to app/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/gorilla/mux"
99

10-
emp "github.com/karanrn/go-rest-api/employee"
10+
emp "github.com/karanrn/go-rest-api/app/employee"
1111
)
1212

1313
func TestGetEmployees(t *testing.T) {
File renamed without changes.

employee/employee.go renamed to app/employee/employee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"strconv"
1111

1212
"github.com/gorilla/mux"
13-
"github.com/karanrn/go-rest-api/database"
13+
"github.com/karanrn/go-rest-api/app/database"
1414
)
1515

1616
// Employee type holds information about an employee

main.go renamed to app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
"github.com/gorilla/mux"
99
"golang.org/x/time/rate"
1010

11-
auth "github.com/karanrn/go-rest-api/authentication"
12-
emp "github.com/karanrn/go-rest-api/employee"
11+
auth "github.com/karanrn/go-rest-api/app/authentication"
12+
emp "github.com/karanrn/go-rest-api/app/employee"
1313
)
1414

1515
const (

docker-compose.yml

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,4 @@ services:
88
volumes:
99
- /home/karan/go/src/github.com/karanrn/go-rest-api/mysql/:/var/lib/mysql
1010
environment:
11-
MYSQL_ROOT_PASSWORD: ${root_password}
12-
# deploy:
13-
# mode: replicated
14-
# replicas: 2
15-
# resources:
16-
# limits:
17-
# cpus: '0.50'
18-
# memory: 500M
11+
MYSQL_ROOT_PASSWORD: ${root_password}

0 commit comments

Comments
 (0)