diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 00000000..f8cc0103 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,71 @@ +name: Build + +on: + push: + branches: + - main + release: + types: + - published + pull_request: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-20.04 + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup Go 1.16 + uses: actions/setup-go@v2 + with: + go-version: 1.16 + + - name: Cache Go modules + uses: actions/cache@v2 + with: + path: ~/go/pkg/mod + key: ${{ runner.os }}-build-${{ hashFiles('**/go.sum') }} + restore-keys: ${{ runner.os }}-build- + + - name: Build Go binary + run: go build -o bin/castai-agent + + - name: Test + run: go test ./... + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push main + if: github.event_name != 'release' + uses: docker/build-push-action@v2 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: castai/agent:${{ github.sha }} + + - name: Get release tag + if: github.event_name == 'release' + run: echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Build and push release + if: github.event_name == 'release' + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: castai/agent:${{ env.RELEASE_TAG }} diff --git a/Dockerfile b/Dockerfile index 17183281..5046ab5c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,3 @@ -FROM golang:alpine AS builder -WORKDIR / -COPY go.mod go.sum main.go ./ -RUN GO111MODULE=on CGO_ENABLED=0 GOOS=linux go build -o castai-agent - FROM alpine:3.13 -COPY --from=builder /castai-agent /usr/local/bin/castai-agent +COPY bin/castai-agent /usr/local/bin/castai-agent CMD ["castai-agent"] - diff --git a/Makefile b/Makefile index f477b958..db59b974 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ build: - go build -o bin/castai-agent + GOOS=linux go build -o bin/castai-agent docker build -t castai/agent:0.0.1 . push: