Skip to content

Commit

Permalink
ci: add ci and DockerHub workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivangShandilya committed Jun 23, 2023
1 parent 7016b2f commit f8ce7a0
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build-test:
name: Build and Test
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: 1.19

- name: Build
run: go build -v .

- name: Test
run: go test -v ./tests
26 changes: 26 additions & 0 deletions .github/workflows/publish-dockerhub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Publish Image to DockerHub

on:
workflow_run:
workflows: ["CI"]
types:
- completed

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: DockerHub Login
uses: docker/[email protected]
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build the Docker image
run: docker build . --file Dockerfile --tag ${{ secrets.DOCKERHUB_USERNAME }}/golang-api

- name: Docker Push
run: docker push ${{ secrets.DOCKERHUB_USERNAME }}/golang-api
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ RUN go mod download
# Copy app files
COPY . .

RUN go build -o go-app
RUN go build -o golang-api

EXPOSE 8000
EXPOSE 8080

CMD ["./go-app"]
CMD ["./golang-api"]
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<<<<<<< HEAD
## Golang API
=======
## Golang API
>>>>>>> db63f1daa2d136d7bf7f37618767faf26270d35e
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import (
"github.com/gin-gonic/gin"
)

var HOST = ":8080"

func main() {
router := gin.Default()
router.GET("/", handler.HomeRoute)
router.GET("/albums", handler.GetAlbums)
router.POST("/albums", handler.PostAlbums)

router.Run("localhost:8080")
router.Run(HOST)
}

0 comments on commit f8ce7a0

Please sign in to comment.