File tree 6 files changed +118
-9
lines changed
6 files changed +118
-9
lines changed Original file line number Diff line number Diff line change 1
1
# Postgres Live
2
- DB_HOST = 127.0.0.1
2
+ DB_HOST = postgres
3
3
DB_DRIVER = postgres
4
- API_SECRET = 98hbun98h # This is used when creating a JWT. It can be anything you want
4
+ API_SECRET = 98hbun98h # Used for creating a JWT. Can be anything
5
5
DB_USER = steven
6
6
DB_PASSWORD =
7
7
DB_NAME = fullstack_api
8
8
DB_PORT = 5432 # Default postgres port
9
9
10
10
# Postgres Test
11
- TestDbHost = 127.0.0.1
11
+ TestDbHost = postgres_test
12
12
TestDbDriver = postgres
13
13
TestApiSecret = 98hbun98h
14
14
TestDbUser = steven
@@ -17,16 +17,16 @@ TestDbName=fullstack_api_test
17
17
TestDbPort = 5432
18
18
19
19
# Mysql Live
20
- # DB_HOST=127.0.0.1
20
+ # DB_HOST=mysql
21
21
# DB_DRIVER=mysql
22
- # API_SECRET=98hbun98h #This is used when creating a JWT. It can be anything you want
22
+ # API_SECRET=98hbun98h #Used for creating a JWT. Can be anything
23
23
# DB_USER=steven
24
24
# DB_PASSWORD=here
25
- # DB_NAME=fullstack_api
25
+ # DB_NAME=fullstack_mysql
26
26
# DB_PORT=3306 #Default mysql port
27
27
28
- # Mysql Test
29
- # TestDbHost=127.0.0.1
28
+ # # Mysql Test
29
+ # TestDbHost=mysql_test
30
30
# TestDbDriver=mysql
31
31
# TestApiSecret=98hbun98h
32
32
# TestDbUser=steven
Original file line number Diff line number Diff line change
1
+ # Start from golang base image
2
+ FROM golang:alpine as builder
3
+
4
+ # ENV GO111MODULE=on
5
+
6
+ # Add Maintainer info
7
+ LABEL maintainer="Steven Victor <chikodi543@gmail.com>"
8
+
9
+ # Install git.
10
+ # Git is required for fetching the dependencies.
11
+ RUN apk update && apk add --no-cache git
12
+
13
+ # Set the current working directory inside the container
14
+ WORKDIR /app
15
+
16
+ # Copy go mod and sum files
17
+ COPY go.mod go.sum ./
18
+
19
+ # RUN go mod tidy
20
+
21
+ # Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed
22
+ RUN go mod download
23
+
24
+ # Copy the source from the current directory to the working Directory inside the container
25
+
26
+ COPY . .
27
+ # Build the Go app
28
+ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
29
+
30
+ # Start a new stage from scratch
31
+ FROM alpine:latest
32
+ RUN apk --no-cache add ca-certificates
33
+
34
+ WORKDIR /root/
35
+
36
+ # Copy the Pre-built binary file from the previous stage
37
+ COPY --from=builder /app/main .
38
+ COPY --from=builder /app/.env .
39
+
40
+ # Expose port 8080 to the outside world
41
+ EXPOSE 8080
42
+
43
+ # Command to run the executable
44
+ CMD ["./main" ]
Original file line number Diff line number Diff line change @@ -12,6 +12,13 @@ import (
12
12
13
13
var server = controllers.Server {}
14
14
15
+ func init () {
16
+ // loads values from .env into the system
17
+ if err := godotenv .Load (); err != nil {
18
+ log .Print ("sad .env file found" )
19
+ }
20
+ }
21
+
15
22
func Run () {
16
23
17
24
var err error
Original file line number Diff line number Diff line change
1
+ version : ' 3'
2
+ services :
3
+ app :
4
+ container_name : full_app
5
+ build : .
6
+ ports :
7
+ - 8080:8080 # Forward the exposed port 8080 on the container to port 8080 on the host machine
8
+ restart : on-failure
9
+ volumes :
10
+ - api:/usr/src/app/
11
+ depends_on :
12
+ - postgres # This service depends on postgres. Start that first.
13
+ # - mysql # This service depends on mysql. Start that first.
14
+ networks :
15
+ - fullstack
16
+
17
+ postgres :
18
+ image : postgres:latest
19
+ container_name : full_db
20
+ environment :
21
+ - POSTGRES_USER=${DB_USER}
22
+ - POSTGRES_PASSWORD=${DB_PASSWORD}
23
+ - POSTGRES_DB=${DB_NAME}
24
+ - DATABASE_HOST=${DB_HOST}
25
+ ports :
26
+ - ' 5432:5432'
27
+ volumes :
28
+ - database_postgres:/var/lib/postgresql/data
29
+ networks :
30
+ - fullstack
31
+
32
+ # mysql:
33
+ # image: mysql:5.7
34
+ # ports:
35
+ # - 3306:3306
36
+ # environment:
37
+ # - MYSQL_DATABASE=${DB_NAME}
38
+ # - MYSQL_USER=${DB_USER}
39
+ # - MYSQL_PASSWORD=${DB_PASSWORD}
40
+ # - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
41
+ # - DATABASE_HOST=${DB_HOST}
42
+ # volumes:
43
+ # - database_mysql:/var/lib/postgresql/data
44
+ # networks:
45
+ # - fullstack
46
+
47
+ volumes :
48
+ api :
49
+ database_postgres :
50
+
51
+ # Networks to be created to facilitate communication between containers
52
+ networks :
53
+ fullstack :
54
+
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
- import "github.com/victorsteven/fullstack/api"
3
+ import (
4
+ "github.com/victorsteven/fullstack/api"
5
+ )
4
6
5
7
func main () {
8
+
6
9
api .Run ()
10
+
7
11
}
You can’t perform that action at this time.
0 commit comments