Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Commit

Permalink
Initialise go module and containerise Motion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
masih committed Jun 27, 2023
1 parent b8ba246 commit ae19f0a
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/container-build.yml
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions .github/workflows/container-publish.yml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
7 changes: 7 additions & 0 deletions cmd/motion/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "fmt"

func main() {
fmt.Println("Hello world from motion!")
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/filecoin-project/motion

go 1.20

0 comments on commit ae19f0a

Please sign in to comment.