Skip to content

Commit

Permalink
Add Dockerfiles and CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean-Der committed Nov 16, 2023
1 parent 339844c commit 14e93c1
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 0 deletions.
Binary file added .github/banner_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/banner_light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Build
on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]
env:
GOVERSION: "1.21.4"

jobs:
integration:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
lfs: true

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/go/bin
~/bin/protoc
~/.cache
key: sip

- name: Build docker image
run: docker build -t sip -f ./build/sip/Dockerfile --build-arg GOVERSION=$GOVERSION --build-arg .
84 changes: 84 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Release to Docker

# Controls when the action will run.
on:
workflow_dispatch:
push:
# only publish on version tags
tags:
- 'v*.*.*'

env:
GOVERSION: "1.21.4"

jobs:
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: |
~/go/pkg/mod
~/go/bin
~/bin/protoc
~/.cache
key: ${{ runner.os }}-sip-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-sip

- name: Docker metadata
id: docker-md
uses: docker/metadata-action@v3
with:
images: livekit/sip
# generate Docker tags based on the following events/attributes
tags: |
type=semver,pattern=v{{version}}
type=semver,pattern=v{{major}}.{{minor}}
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.21"

- name: Download Go modules
run: go mod download

- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- 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_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v2
with:
context: .
file: ./build/sip/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.docker-md.outputs.tags }}
labels: ${{ steps.docker-md.outputs.labels }}
build-args: |
GOVERSION=${{ env.GOVERSION }}
38 changes: 38 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Test
on:
workflow_dispatch:
pull_request:
branches: [ main ]

jobs:
test:
runs-on: buildjet-8vcpu-ubuntu-2204

steps:
- uses: actions/checkout@v3

- name: Build docker image
run: |
docker build \
-t sip-test \
-f ./build/test/Dockerfile .
- name: Run tests
run: |
docker run --rm \
-e GITHUB_WORKFLOW=1 \
sip-test
53 changes: 53 additions & 0 deletions build/sip/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

ARG GOVERSION

FROM golang:$GOVERSION

ARG TARGETPLATFORM

WORKDIR /workspace

# install libopus
RUN apt-get update && apt-get install -y pkg-config libopus-dev libopusfile-dev

# download go modules
COPY go.mod .
COPY go.sum .
RUN go mod download

# copy source
COPY cmd/ cmd/
COPY pkg/ pkg/
COPY version/ version/

# build
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then GOARCH=arm64; else GOARCH=amd64; fi && \
CGO_ENABLED=1 GOOS=linux GOARCH=${GOARCH} GO111MODULE=on go build -a -o sip ./cmd/server

FROM golang:$GOVERSION

# install wget for health check
RUN apt-get update && apt-get install -y pkg-config libopus-dev libopusfile-dev wget

# clean up
RUN apt-get clean && \
rm -rf /var/lib/apt/lists/*

# copy binary
COPY --from=0 /workspace/sip /bin/

# run
ENTRYPOINT ["sip"]
41 changes: 41 additions & 0 deletions build/test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM livekit/gstreamer:1.20.4-dev

ARG TARGETPLATFORM

WORKDIR /workspace

# install deps
RUN apt-get update && \
apt-get install -y \
curl

RUN if [ "$TARGETPLATFORM" = "linux/arm64" ]; then GOARCH=arm64; else GOARCH=amd64; fi && \
curl -L -o /tmp/go.tar.gz "https://go.dev/dl/go1.20.7.linux-$GOARCH.tar.gz"
RUN tar -C /usr/local -xzf /tmp/go.tar.gz
ENV PATH="$PATH:/usr/local/go/bin"

# download go modules
COPY go.mod .
COPY go.sum .
RUN go mod download

# copy source
COPY pkg/ pkg/
COPY version/ version/

COPY build/test/entrypoint.sh .
ENTRYPOINT ["./entrypoint.sh"]
25 changes: 25 additions & 0 deletions build/test/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Copyright 2023 LiveKit, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -exo pipefail


# Run tests
if [[ -z "${GITHUB_WORKFLOW}" ]]; then
exec go test -v -timeout 20m ./pkg/...
else
go install github.com/gotesttools/gotestfmt/v2/cmd/gotestfmt@latest
exec go tool test2json -p sip go test -test.v=true -test.timeout 20m ./pkg/... 2>&1 | "$HOME"/go/bin/gotestfmt
fi

0 comments on commit 14e93c1

Please sign in to comment.