Skip to content

Commit 5e4e832

Browse files
Lairon Acosta GuardiasLairon Acosta Guardias
Lairon Acosta Guardias
authored and
Lairon Acosta Guardias
committed
feat: add git actions config to deploy in ecs and created simple go app
1 parent 4bb3b26 commit 5e4e832

File tree

8 files changed

+282
-0
lines changed

8 files changed

+282
-0
lines changed

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# Created by https://www.toptal.com/developers/gitignore/api/go
2+
# Edit at https://www.toptal.com/developers/gitignore?templates=go
3+
4+
### Go ###
15
# Binaries for programs and plugins
26
*.exe
37
*.exe~
@@ -13,3 +17,12 @@
1317

1418
# Dependency directories (remove the comment below to include it)
1519
# vendor/
20+
21+
### Go Patch ###
22+
/vendor/
23+
/Godeps/
24+
25+
### ide config ###
26+
.idea
27+
28+
# End of https://www.toptal.com/developers/gitignore/api/go

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Start from golang base image
2+
FROM golang:alpine as builder
3+
4+
# Add Maintainer info
5+
LABEL maintainer="Lairon Acosta <[email protected]>"
6+
7+
# Install git.
8+
# Git is required for fetching the dependencies.
9+
RUN apk update && apk add --no-cache git
10+
11+
# Set the current working directory inside the container
12+
WORKDIR /app
13+
14+
# Copy go mod and sum files
15+
COPY go.mod go.sum ./
16+
17+
# Download all dependencies. Dependencies will be cached if the go.mod and the go.sum files are not changed
18+
RUN go mod download
19+
20+
# Copy the source from the current directory to the working Directory inside the container
21+
COPY . .
22+
23+
# Build the Go app
24+
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .
25+
26+
# Start a new stage from scratch
27+
FROM alpine:latest
28+
RUN apk --no-cache add ca-certificates
29+
30+
WORKDIR /root/
31+
32+
# Copy the Pre-built binary file from the previous stage. Observe we also copied the .env file
33+
COPY --from=builder /app/main .
34+
35+
# Expose port 8080 to the outside world
36+
EXPOSE 8080
37+
38+
#Command to run the executable
39+
CMD ["./main"]

controllers/health_controller.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package controllers
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"net/http"
6+
)
7+
8+
func Health(c *gin.Context) {
9+
c.JSON(http.StatusOK, gin.H{"message": "ok"})
10+
}

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/laironacosta/ms-gin-go
2+
3+
go 1.16
4+
5+
require github.com/gin-gonic/gin v1.6.3

go.sum

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3+
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
5+
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
6+
github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14=
7+
github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M=
8+
github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
9+
github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
10+
github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q=
11+
github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8=
12+
github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no=
13+
github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA=
14+
github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY=
15+
github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI=
16+
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
17+
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
18+
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
19+
github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns=
20+
github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
21+
github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y=
22+
github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII=
23+
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
24+
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
25+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
26+
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
27+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg=
28+
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
29+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
30+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
31+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
32+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
33+
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
34+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
35+
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
36+
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
37+
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
38+
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
39+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
40+
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
41+
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
42+
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
43+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
44+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
45+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
46+
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
47+
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

main.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/laironacosta/ms-gin-go/router"
6+
)
7+
8+
func main() {
9+
gin := gin.Default()
10+
11+
r := router.NewRouter(gin)
12+
r.Init()
13+
14+
gin.Run() // listen and serve on 0.0.0.0:8080
15+
}

router/router.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package router
2+
3+
import (
4+
"github.com/gin-gonic/gin"
5+
"github.com/laironacosta/ms-gin-go/controllers"
6+
)
7+
8+
type Router struct {
9+
server *gin.Engine
10+
}
11+
12+
func NewRouter(server *gin.Engine) *Router {
13+
return &Router{
14+
server,
15+
}
16+
}
17+
18+
func (r *Router) Init() {
19+
//create a default router with default middleware
20+
basePath := r.server.Group("/git-deploy-aws-ecs")
21+
22+
basePath.GET("/health", controllers.Health)
23+
}

task-definition.json

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
{
2+
"ipcMode": null,
3+
"executionRoleArn": "arn:aws:iam::027479467189:role/ecsTaskExecutionRole",
4+
"containerDefinitions": [
5+
{
6+
"dnsSearchDomains": null,
7+
"environmentFiles": null,
8+
"logConfiguration": {
9+
"logDriver": "awslogs",
10+
"secretOptions": null,
11+
"options": {
12+
"awslogs-group": "/ecs/git-deploy-aws-ecs-task-definition",
13+
"awslogs-region": "us-east-2",
14+
"awslogs-stream-prefix": "ecs"
15+
}
16+
},
17+
"entryPoint": [],
18+
"portMappings": [
19+
{
20+
"hostPort": 80,
21+
"protocol": "tcp",
22+
"containerPort": 80
23+
}
24+
],
25+
"command": [],
26+
"linuxParameters": null,
27+
"cpu": 256,
28+
"environment": [],
29+
"resourceRequirements": null,
30+
"ulimits": null,
31+
"dnsServers": null,
32+
"mountPoints": [],
33+
"workingDirectory": null,
34+
"secrets": null,
35+
"dockerSecurityOptions": null,
36+
"memory": null,
37+
"memoryReservation": 512,
38+
"volumesFrom": [],
39+
"stopTimeout": null,
40+
"image": "027479467189.dkr.ecr.us-east-2.amazonaws.com/git-deploy-aws-ecs",
41+
"startTimeout": null,
42+
"firelensConfiguration": null,
43+
"dependsOn": null,
44+
"disableNetworking": null,
45+
"interactive": null,
46+
"healthCheck": null,
47+
"essential": true,
48+
"links": [],
49+
"hostname": null,
50+
"extraHosts": null,
51+
"pseudoTerminal": null,
52+
"user": null,
53+
"readonlyRootFilesystem": null,
54+
"dockerLabels": null,
55+
"systemControls": null,
56+
"privileged": null,
57+
"name": "git-deploy-aws-ecs-container"
58+
}
59+
],
60+
"placementConstraints": [],
61+
"memory": "512",
62+
"taskRoleArn": null,
63+
"compatibilities": [
64+
"EC2",
65+
"FARGATE"
66+
],
67+
"taskDefinitionArn": "arn:aws:ecs:us-east-2:027479467189:task-definition/git-deploy-aws-ecs-task-definition:1",
68+
"family": "git-deploy-aws-ecs-task-definition",
69+
"requiresAttributes": [
70+
{
71+
"targetId": null,
72+
"targetType": null,
73+
"value": null,
74+
"name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
75+
},
76+
{
77+
"targetId": null,
78+
"targetType": null,
79+
"value": null,
80+
"name": "ecs.capability.execution-role-awslogs"
81+
},
82+
{
83+
"targetId": null,
84+
"targetType": null,
85+
"value": null,
86+
"name": "com.amazonaws.ecs.capability.ecr-auth"
87+
},
88+
{
89+
"targetId": null,
90+
"targetType": null,
91+
"value": null,
92+
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
93+
},
94+
{
95+
"targetId": null,
96+
"targetType": null,
97+
"value": null,
98+
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
99+
},
100+
{
101+
"targetId": null,
102+
"targetType": null,
103+
"value": null,
104+
"name": "ecs.capability.execution-role-ecr-pull"
105+
},
106+
{
107+
"targetId": null,
108+
"targetType": null,
109+
"value": null,
110+
"name": "com.amazonaws.ecs.capability.docker-remote-api.1.18"
111+
},
112+
{
113+
"targetId": null,
114+
"targetType": null,
115+
"value": null,
116+
"name": "ecs.capability.task-eni"
117+
}
118+
],
119+
"pidMode": null,
120+
"requiresCompatibilities": [
121+
"FARGATE"
122+
],
123+
"networkMode": "awsvpc",
124+
"cpu": "256",
125+
"revision": 1,
126+
"status": "ACTIVE",
127+
"inferenceAccelerators": null,
128+
"proxyConfiguration": null,
129+
"volumes": []
130+
}

0 commit comments

Comments
 (0)