Skip to content

Commit

Permalink
Merge pull request #2 from castai/workflow
Browse files Browse the repository at this point in the history
ci: add github workflow
  • Loading branch information
saumas authored Mar 4, 2021
2 parents 2be696e + 35f6b01 commit a44e772
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 8 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
8 changes: 1 addition & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit a44e772

Please sign in to comment.