Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.png
*.gif
*.webp
*.avif
out/
tmp/
*.yaml
!example.config.yaml
!docker-compose.yaml
!.github/**/*.yaml
*-gqlgen.go
*_gen.go
node_modules/
internal/rest/v*/docs
.vscode/
go.work
go.work.sum
41 changes: 41 additions & 0 deletions .github/dependabot.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "/"
target-branch: dev
schedule:
interval: weekly
reviewers:
- anatoleam
- troydota
- package-ecosystem: github-actions
directory: "/"
target-branch: dev
schedule:
interval: weekly
reviewers:
- anatoleam
- troydota
- package-ecosystem: docker
directory: "/build"
target-branch: dev
schedule:
interval: weekly
reviewers:
- anatoleam
- troydota
- package-ecosystem: gomod
directory: "/scripts/gen_github_action_config"
target-branch: dev
schedule:
interval: weekly
reviewers:
- troydota
- package-ecosystem: npm
directory: "/docs"
target-branch: dev
schedule:
interval: monthly
reviewers:
- anatoleam
- troydota
247 changes: 247 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
name: API Lint, Build, Test, Deploy

on:
push:
branches:
- master
- dev
pull_request:
workflow_dispatch:
inputs:
deploy:
description: "Deploy location"
required: true
default: "none"
type: choice
options:
- production
- staging
- none

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
concurrency:
group: ${{ github.workflow }}-lint-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.18.2

- uses: actions/setup-node@v3
with:
node-version: "18"

- name: Checkout code
uses: actions/checkout@v3

- id: cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"

- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.cache-paths.outputs.go-build }}
key: ${{ runner.os }}-go-build-${{ hashFiles('go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v3
with:
path: ${{ steps.cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('go.sum') }}

- name: Node Modules Cache
uses: actions/cache@v3
with:
path: node_modules
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}

- name: install deps
run: make deps

- name: install dev_deps
run: make dev_deps

- name: Generate structures
run: make generate

- name: Run Lint
run: make lint

post-lint:
runs-on: ubuntu-latest
needs:
- lint
if: ${{ failure() }}

steps:
- name: Cancel current workflow run
uses: actions/github-script@v6
with:
script: |
github.actions.cancelWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId
})

build:
name: Build and Test
runs-on: self-hosted
concurrency:
group: ${{ github.workflow }}-build-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive

- id: buildx-context
run: |
docker context create builders

- uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
endpoint: builders

- name: Build docker image
uses: docker/build-push-action@v3
with:
context: .
cache-from: |
type=gha
cache-to: |
type=gha,mode=max
tags: |
api:${{ github.sha }}
build-args: |
"BUILDER=${{ github.actor }}"
"VERSION=${{ github.sha }}"
outputs: |
type=docker,dest=image.tar
target: final

- name: Upload docker image
uses: actions/upload-artifact@v3
with:
name: docker-image
path: image.tar
retention-days: 3

deploy:
name: Deploy
needs:
- build
- lint
env:
DEPLOY_PROD: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'production') || (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'master') }}
DEPLOY_STAGE: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy == 'staging') || (github.event_name == 'push' && github.ref_type == 'branch' && github.ref_name == 'dev') }}
if: ${{ (github.event_name == 'workflow_dispatch' && github.event.inputs.deploy != 'none') || (github.event_name == 'push' && github.ref_type == 'branch' && (github.ref_name == 'master' || github.ref_name == 'dev')) }}
runs-on: self-hosted
concurrency:
group: ${{ github.workflow }}-deploy-${{ github.ref }}
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v3

- id: buildx-context
run: |
docker context create builders

- uses: docker/setup-buildx-action@v2
id: buildx
with:
install: true
endpoint: builders

- name: Download artifact
uses: actions/download-artifact@v3
with:
name: docker-image

- name: Load image
run: |
docker load --input image.tar
docker image ls -a

- name: Log into Harbor Registry
uses: docker/login-action@v2
with:
registry: harbor.disembark.dev
username: robot$deploy-7tv
password: ${{ secrets.REGISTRY_TOKEN }}

- name: Install kubectl
uses: azure/setup-kubectl@v2.1

- name: "[Production] Tag & Push docker images"
if: ${{ env.DEPLOY_PROD == 'true' }}
run: |
docker tag api:${{ github.sha }} harbor.disembark.dev/7tv/api:latest
docker tag api:${{ github.sha }} harbor.disembark.dev/7tv/api:${{ github.sha }}
docker push harbor.disembark.dev/7tv/api:latest
docker push harbor.disembark.dev/7tv/api:${{ github.sha }}

- name: "[Production] Update deployment template"
uses: danielr1996/envsubst-action@1.1.0
if: ${{ env.DEPLOY_PROD == 'true' }}
env:
IMAGE_TAG: ${{ github.sha }}
with:
input: k8s/prod.template.yaml
output: k8s/prod.yaml

- name: "[Production] Deploy to k8s"
if: ${{ env.DEPLOY_PROD == 'true' }}
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBECONFIG }}
run: |
mkdir -p ~/.kube
(echo $KUBE_CONFIG_DATA | base64 -d) >> ~/.kube/config
kubectl config use-context autodeploy@SevenTV

kubectl apply -f k8s/prod.yaml

- name: "[Staging] Tag & Push docker images"
if: ${{ env.DEPLOY_STAGE == 'true' }}
run: |
docker tag api:${{ github.sha }} harbor.disembark.dev/7tv-stage/api:latest
docker tag api:${{ github.sha }} harbor.disembark.dev/7tv-stage/api:${{ github.sha }}
docker push harbor.disembark.dev/7tv-stage/api:latest
docker push harbor.disembark.dev/7tv-stage/api:${{ github.sha }}

- name: "[Staging] Update deployment template"
uses: danielr1996/envsubst-action@1.1.0
if: ${{ env.DEPLOY_STAGE == 'true' }}
env:
IMAGE_TAG: ${{ github.sha }}
with:
input: k8s/dev.template.yaml
output: k8s/dev.yaml

- name: "[Staging] Deploy to k8s"
if: ${{ env.DEPLOY_STAGE == 'true' }}
env:
KUBE_CONFIG_DATA: ${{ secrets.KUBECONFIG_STAGE }}
run: |
mkdir -p ~/.kube
(echo $KUBE_CONFIG_DATA | base64 -d) >> ~/.kube/config
kubectl config use-context autodeploy@SevenTV

kubectl apply -f k8s/dev.yaml
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
*.png
*.gif
*.webp
*.avif
out/
tmp/
*.yaml
!example.config.yaml
!docker-compose.yaml
!.github/**/*.yaml
*-gqlgen.go
*_gen.go
node_modules/
internal/rest/v*/docs
.vscode/
go.work
go.work.sum
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Ignore docs
internal/rest/v*/docs/*
.vscode/
58 changes: 58 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# The base image used to build all other images
ARG BASE_IMG=ubuntu:22.04
# The tag to use for golang image
ARG GOLANG_TAG=1.18.2

#
# Download and install all deps required to run tests and build the go application
#
FROM golang:$GOLANG_TAG as go

FROM $BASE_IMG as go-builder
WORKDIR /tmp/build

# update the apt repo and install any deps we might need.
RUN apt-get update && \
apt-get install -y \
build-essential \
make \
git && \
apt-get autoremove -y && \
apt-get clean -y && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*

ENV PATH /usr/local/go/bin:$PATH
ENV GOPATH /go
ENV PATH $GOPATH/bin:$PATH
COPY --from=go /usr/local /usr/local
COPY --from=go /go /go

COPY go.mod .
COPY go.sum .
COPY Makefile .

RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH" && \
make deps

COPY . .

RUN make generate && \
make test

ARG BUILDER
ARG VERSION

ENV IMAGES_BUILDER=${BUILDER}
ENV IMAGES_VERSION=${VERSION}

RUN make

#
# final squashed image
#
FROM $BASE_IMG as final
WORKDIR /app

COPY --from=go-builder /tmp/build/out .

CMD ./api
Loading