Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore/ci #9

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
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
108 changes: 104 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,113 @@ jobs:
with:
go-version: 1.17

- name: Build
run: |
make bin/image-cache-daemon bin/warden
- run: GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-w -s" -o bin/image-cache-daemon-amd64 main.go
- run: GOARCH=arm64 CGO_ENABLED=0 go build -ldflags="-w -s" -o bin/image-cache-daemon-arm64 main.go
- run: GOARCH=arm CGO_ENABLED=0 go build -ldflags="-w -s" -o bin/image-cache-daemon-arm main.go

- uses: actions/upload-artifact@v2
with:
name: builds
path: bin/

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-test-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-test-
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Test
run: go test -v ./...


# Always build images just to ensure that they're buildable,
# but only push them to the registry if this is a push to master
build-images:
runs-on: ubuntu-latest
# needs:
# - test
# - lint
# - e2e
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- run: env
- name: Login to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Warden Image
uses: docker/build-push-action@v2
with:
file: Dockerfile.warden
push: ${{ github.event_name == 'push'}}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
ghcr.io/dcherman/image-cache-daemon-warden:latest
ghcr.io/dcherman/image-cache-daemon-warden:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Build Image Cache Daemon Image
uses: docker/build-push-action@v2
with:
file: Dockerfile
push: ${{ github.event_name == 'push'}}
platforms: linux/amd64,linux/arm64,linux/arm/v7
tags: |
ghcr.io/dcherman/image-cache-daemon:latest
ghcr.io/dcherman/image-cache-daemon:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max


e2e:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- uses: nolar/setup-k3d-k3s@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build Warden Image
uses: docker/build-push-action@v2
with:
file: Dockerfile.warden
load: true
tags: |
ghcr.io/dcherman/image-cache-daemon-warden:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build Image Cache Daemon Image
uses: docker/build-push-action@v2
with:
file: Dockerfile
load: true
tags: |
ghcr.io/dcherman/image-cache-daemon:latest
cache-from: type=gha
cache-to: type=gha,mode=max

- run: k3d image import ghcr.io/dcherman/image-cache-daemon:latest
- run: k3d image import ghcr.io/dcherman/image-cache-daemon-warden:latest

lint:
runs-on: ubuntu-latest
steps:
Expand Down
97 changes: 97 additions & 0 deletions manifests/base/install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: image-cache-daemon
spec:
selector:
matchLabels:
app: image-cache-daemon
template:
metadata:
labels:
app: image-cache-daemon
spec:
serviceAccountName: image-cache-daemon
containers:
- name: image-cache-daemon
image: exiges/image-cache-daemon:latest
imagePullPolicy: Always
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: POD_UID
valueFrom:
fieldRef:
fieldPath: metadata.uid
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: image-cache-daemon
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: image-cache-daemon-cluster-role
rules:
- apiGroups:
- argoproj.io
resources:
- workflowtemplates
- cronworkflows
- clusterworkflowtemplates
verbs:
- get
- list
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: image-cache-daemon-cluster-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: image-cache-daemon-cluster-role
subjects:
- kind: ServiceAccount
name: image-cache-daemon
namespace: image-cache-daemon
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: image-cache-daemon-role
rules:
- apiGroups:
- ""
resources:
- pods
verbs:
- get
- list
- watch
- delete
- create
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: image-cache-daemon-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: image-cache-daemon-role
subjects:
- kind: ServiceAccount
name: image-cache-daemon
2 changes: 2 additions & 0 deletions manifests/base/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
- install.yaml
11 changes: 11 additions & 0 deletions manifests/ci/ds.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: image-cache-daemon
spec:
template:
spec:
containers:
- name: image-cache-daemon
args:
- --warden-image=warden:ci
10 changes: 10 additions & 0 deletions manifests/ci/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
images:
- name: exiges/image-cache-daemon
newName: image-cache-daemon
newTag: ci

resources:
- ../base

patchesStrategicMerge:
- ds.yaml
40 changes: 40 additions & 0 deletions test/e2e/node_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"os"

"os/exec"
"testing"

"github.com/stretchr/testify/assert"
)

func runCommandWithOutput(command string, args ...string) error {
cmd := exec.Command(command, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd.Run()
}

func TestImageCaching(t *testing.T) {
t.SkipNow()

err := runCommandWithOutput("k3d", "cluster", "create", "foobar", "--no-lb")

if !assert.NoError(t, err) {
return
}

t.Cleanup(func() {
if err := runCommandWithOutput("k3d", "cluster", "delete", "foobar"); err != nil {
t.Errorf("failed to cleanup test cluster: %v", err)
}
})

err = runCommandWithOutput("docker", "build", "-f", "Dockerfile.warden", "-t", "warden:ci", ".")

if !assert.NoError(t, err) {
return
}
}