Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
ci: deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed May 13, 2023
1 parent 7404771 commit 4d33bda
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 8 deletions.
109 changes: 109 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: deploy

on:
push:
branches: [main]
workflow_dispatch:

env:
REGISTRY: ghcr.io
IMAGE_TAG: ghcr.io/${{ github.repository }}
KUBECTL_VERSION: v1.27.1

jobs:
deploy:
environment: prod
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
env:
KUBECONFIG: /tmp/kubeconfig

# Skip deploy commit message contains #skip
if: ${{ !contains(github.event.head_commit.message, '!skip') }}

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

- uses: docker/setup-buildx-action@v2

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: "1.20.4"
cache: false

- name: Get Go environment
id: go-env
run: |
echo "cache=$(go env GOCACHE)" >> $GITHUB_ENV
echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_ENV
echo "goversion=$(go env GOVERSION)" >> $GITHUB_ENV
- name: Set up cache
uses: actions/cache@v3
with:
path: |
${{ env.cache }}
${{ env.modcache }}
key: release-${{ runner.os }}-go-${{ env.goversion }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
release-${{ runner.os }}-go-${{ env.goversion }}
- name: Docker log in
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Get short commit SHA
id: var
shell: bash
run: |
echo "sha=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Go build
run: make build

- name: Application image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: "${{ env.IMAGE_TAG }}:${{ env.sha }}"
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Generate deployment with SHA version
run: sed 's/:main/:${{ env.sha }}/g' .k8s/deployment.yml > .k8s/deployment.release.yml

- name: Set up kubectl cache
uses: actions/cache@v3
with:
path: /tmp/kubectl
key: kubectl-${{ env.KUBECTL_VERSION }}

- name: Check kubectl
id: "kubectl"
uses: andstor/file-existence-action@v2
with:
files: /tmp/kubectl

- name: Download kubectl
if: steps.kubectl.outputs.files_exists != 'true'
run: |
wget -O /tmp/kubectl "https://dl.k8s.io/release/${{ env.KUBECTL_VERSION }}/bin/linux/amd64/kubectl"
chmod +x /tmp/kubectl
- name: Setup kubeconfig
env:
KUBE: ${{ secrets.KUBE }}
run: .k8s/kubeconfig.sh

- name: Deploy
run: |
/tmp/kubectl apply -f .k8s/deployment.release.yml
/tmp/kubectl -n faster rollout status deployment/gh-archive-yt --timeout=10m
7 changes: 6 additions & 1 deletion .k8s/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,13 @@ spec:
value: 0.0.0.0:8080
- name: METRICS_ADDR
value: 0.0.0.0:8090
- name: YT_ADDR
- name: YT_PROXY
value: http-proxies.yt.svc.cluster.local
- name: YT_TOKEN
valueFrom:
secretKeyRef:
name: gh-archive-yt
key: YT_TOKEN
- name: GITHUB_TOKEN
valueFrom:
secretKeyRef:
Expand Down
10 changes: 3 additions & 7 deletions cmd/gh-archive-yt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

type Service struct {
ytAddr string
token string
lg *zap.Logger
batches chan []gh.Event
Expand All @@ -48,7 +47,6 @@ type Event struct {
func (c *Service) Send(ctx context.Context) error {
tablePathEvents := ypath.Path("//go-faster").Child("github_events")
yc, err := ythttp.NewClient(&yt.Config{
Proxy: c.ytAddr,
Logger: &ytzap.Logger{L: zctx.From(ctx)},
})
if err != nil {
Expand Down Expand Up @@ -228,11 +226,9 @@ func main() {
}

s := &Service{
batches: make(chan []gh.Event, 5),
lg: lg,
ytAddr: os.Getenv("YT_ADDR"),
token: os.Getenv("GITHUB_TOKEN"),

batches: make(chan []gh.Event, 5),
lg: lg,
token: os.Getenv("GITHUB_TOKEN"),
missCount: missCount,
fetchedCount: fetchedCount,
}
Expand Down

0 comments on commit 4d33bda

Please sign in to comment.