Skip to content

Commit

Permalink
feat(ci): ✨ creating build push docker pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
vict0rcarvalh0 committed Jun 14, 2024
1 parent 2dfafe6 commit 2a52af0
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 15 deletions.
63 changes: 48 additions & 15 deletions .github/workflows/act.yml
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 }}
14 changes: 14 additions & 0 deletions src/sample-go-docker/Dockerfile
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"]
3 changes: 3 additions & 0 deletions src/sample-go-docker/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module cicd

go 1.22.3
16 changes: 16 additions & 0 deletions src/sample-go-docker/main.go
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))
}
29 changes: 29 additions & 0 deletions src/sample-go-docker/main_test.go
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)
}
}

0 comments on commit 2a52af0

Please sign in to comment.