-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ci): ✨ creating build push docker pipeline
- Loading branch information
1 parent
2dfafe6
commit 2a52af0
Showing
5 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,59 @@ | ||
name: Node.js CI - Testing Act | ||
'on': | ||
name: CI Go | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.22" # Versão do Go 1.22 | ||
- name: Build | ||
working-directory: src/sample-go-docker | ||
run: go build -o main . | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v2 | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
node-version: '14' | ||
go-version: "1.22.3" | ||
- name: Install golangci-lint | ||
working-directory: src/sample-go-docker | ||
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.54.2 | ||
- name: Run golangci-lint | ||
working-directory: src/sample-go-docker | ||
run: golangci-lint run | ||
|
||
- name: Install dependencies | ||
working-directory: src/sample-frontend-react | ||
run: npm install | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-go@v3 | ||
with: | ||
go-version: "1.22" | ||
- name: Run tests | ||
working-directory: src/sample-go-docker | ||
run: go test -v ./... | ||
|
||
- name: Build the React app | ||
working-directory: src/sample-frontend-react | ||
run: npm run build | ||
deploy: | ||
runs-on: ubuntu-latest | ||
needs: [build, lint, test, security] | ||
environment: production | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Build and push Docker image | ||
run: | | ||
docker build -t src/sample-go-docker . | ||
docker push src/sample-go-docker | ||
# - name: Deploy to Render.com | ||
# uses: render-actions/deploy@v1 | ||
# with: | ||
# service-id: ${{ secrets.RENDER_SERVICE_ID }} | ||
# api-key: ${{ secrets.RENDER_API_KEY }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Dockerfile | ||
FROM golang:alpine | ||
|
||
WORKDIR /app | ||
|
||
COPY main.go main_test.go ./ | ||
|
||
RUN go mod init myapp | ||
RUN go mod tidy | ||
RUN go build -o main main.go | ||
|
||
EXPOSE 8080 | ||
|
||
CMD ["go", "run", "main.go"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module cicd | ||
|
||
go 1.22.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func handler(w http.ResponseWriter, r *http.Request) { | ||
fmt.Fprintf(w, "Victor!") | ||
} | ||
|
||
func main() { | ||
http.HandleFunc("/", handler) | ||
log.Fatal(http.ListenAndServe(":8080", nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package main | ||
|
||
import ( | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
) | ||
|
||
func TestHandler(t *testing.T) { | ||
req, err := http.NewRequest("GET", "/", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
rr := httptest.NewRecorder() | ||
handler := http.HandlerFunc(handler) | ||
handler.ServeHTTP(rr, req) | ||
|
||
if status := rr.Code; status != http.StatusOK { | ||
t.Errorf("handler returned wrong status code: got %v want %v", | ||
status, http.StatusOK) | ||
} | ||
|
||
expected := "Hello, World!" | ||
if rr.Body.String() != expected { | ||
t.Errorf("handler returned unexpected body: got %v want %v", | ||
rr.Body.String(), expected) | ||
} | ||
} |