From ae19f0a20b11f71b16e76b4c53c53c2e5a3dc402 Mon Sep 17 00:00:00 2001 From: "Masih H. Derkani" Date: Tue, 27 Jun 2023 20:44:31 +0100 Subject: [PATCH] Initialise go module and containerise Motion Define Motion go module, and add the initial dockerfile with two CI builds: one to build the container on PR, and one to publish it to ghcr.io for user convenience. --- .github/workflows/container-build.yml | 18 ++++++++++ .github/workflows/container-publish.yml | 44 +++++++++++++++++++++++++ Dockerfile | 13 ++++++++ cmd/motion/main.go | 7 ++++ go.mod | 3 ++ 5 files changed, 85 insertions(+) create mode 100644 .github/workflows/container-build.yml create mode 100644 .github/workflows/container-publish.yml create mode 100644 Dockerfile create mode 100644 cmd/motion/main.go create mode 100644 go.mod diff --git a/.github/workflows/container-build.yml b/.github/workflows/container-build.yml new file mode 100644 index 0000000..bce4991 --- /dev/null +++ b/.github/workflows/container-build.yml @@ -0,0 +1,18 @@ +name: Build + +on: [ pull_request ] + +jobs: + build: + name: Container + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Build Container image + uses: docker/build-push-action@v3 + with: + context: . + push: false \ No newline at end of file diff --git a/.github/workflows/container-publish.yml b/.github/workflows/container-publish.yml new file mode 100644 index 0000000..14fe334 --- /dev/null +++ b/.github/workflows/container-publish.yml @@ -0,0 +1,44 @@ +name: Publish + +on: + push: + branches: + - main + release: + types: + - published + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + +jobs: + build-and-push-image: + name: Container + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - name: Checkout repository + uses: actions/checkout@v3 + - name: Log in to the Container registry + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + tags: | + type=semver,pattern={{version}} + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..50d202c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM golang:1.20-bullseye as build + +WORKDIR /go/src/motion +COPY go.* ./ +RUN go mod download + +COPY . . +RUN go build -o /go/bin/motion ./cmd/motion + +FROM gcr.io/distroless/static-debian11 +COPY --from=build /go/bin/motion /usr/bin/ + +ENTRYPOINT ["/usr/bin/motion"] diff --git a/cmd/motion/main.go b/cmd/motion/main.go new file mode 100644 index 0000000..2dde463 --- /dev/null +++ b/cmd/motion/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world from motion!") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8dd46f5 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/filecoin-project/motion + +go 1.20