diff --git a/.github/workflow/dockerimage.yml b/.github/workflow/dockerimage.yml new file mode 100644 index 0000000..c845522 --- /dev/null +++ b/.github/workflow/dockerimage.yml @@ -0,0 +1,14 @@ +name: Docker Image CI + +on: [push] + +jobs: + + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Unit test + run: auto/test + - name: Build the Docker image + run: auto/build diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9f2e3a7 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.13-alpine3.10 AS build + +RUN apk add --no-cache git openssh + +ENV GOOS=linux +ENV GOARCH=amd64 + +WORKDIR /app/zendesk + +COPY . . + +RUN go mod download +RUN go build -o bin/app main.go + +FROM alpine:3.10 + +RUN adduser -D -u 1000 zendesk + +WORKDIR /home/zendesk + +USER zendesk + +COPY --from=build /app/zendesk/bin/app . + +CMD [ "/home/zendesk/app" ] diff --git a/auto/build b/auto/build new file mode 100755 index 0000000..149fe9a --- /dev/null +++ b/auto/build @@ -0,0 +1,8 @@ +#!/bin/bash -eu + +cd $(dirname $0)/.. + + +VERSION=1.0.${GITHUB_RUN_NUMBER-1} + +docker build . --file Dockerfile --tag junwei-zhao/zendesk:${VERSION} diff --git a/auto/test b/auto/test new file mode 100755 index 0000000..581ac28 --- /dev/null +++ b/auto/test @@ -0,0 +1,5 @@ +#!/bin/bash -eu + +cd $(dirname $0)/.. + +docker-compose run --rm app go test ./... -cover diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..cbe7c46 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,11 @@ +version: "3" +services: + app: + image: golang:1.13 + working_dir: /app/zendesk + volumes: + - .:/app/zendesk + - go-libs:/go/pkg + command: ["sh", "-c", "go run main.go"] +volumes: + go-libs: {} diff --git a/main.go b/main.go new file mode 100644 index 0000000..b952421 --- /dev/null +++ b/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("I am placeholder of application") +} diff --git a/search/parse.go b/search/parse.go index 57f65b8..7fb644d 100644 --- a/search/parse.go +++ b/search/parse.go @@ -3,12 +3,28 @@ package search import ( "encoding/json" "fmt" + "io/ioutil" "github.com/wahyd4/zendesk/model" "github.com/wahyd4/zendesk/view" ) +// type dataHandler func(jsonContent []byte) error + func (app *APP) Parse(jsonFiles []string) error { + // dataHandlers := map[string]dataHandler{ + // "organisations": app.LoadOrganisationsFromJSON, + // "users": app.LoadUsersFromJSON, + // "tickets": app.LoadTicketsFromJSON, + // } + + for _, file := range jsonFiles { + _, err := ioutil.ReadFile(file) + if err != nil { + return fmt.Errorf("failed to read %s data file with error: %s", file, err.Error()) + } + + } return nil }