diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..83bf6a5 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/.github/workflows/publish-dockerhub.yaml b/.github/workflows/publish-dockerhub.yaml new file mode 100644 index 0000000..02de138 --- /dev/null +++ b/.github/workflows/publish-dockerhub.yaml @@ -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/login-action@v2.1.0 + 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 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 93414b6..2e24c6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] diff --git a/README.md b/README.md index e69de29..40841b9 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,5 @@ +<<<<<<< HEAD +## Golang API +======= +## Golang API +>>>>>>> db63f1daa2d136d7bf7f37618767faf26270d35e diff --git a/main.go b/main.go index 31ba03c..daebb84 100644 --- a/main.go +++ b/main.go @@ -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) }