Skip to content

Commit

Permalink
Add release flow
Browse files Browse the repository at this point in the history
Signed-off-by: zeroalphat <taichi-takemura@cybozu.co.jp>
  • Loading branch information
zeroalphat committed Nov 8, 2023
1 parent ab536a4 commit 441a77e
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 27 deletions.
30 changes: 30 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
changelog:
exclude:
labels:
- ignore-for-release
- ci
- documentation
- refactoring
- test
categories:
- title: Features
labels:
- enhancement
- title: Bug Fixes
labels:
- bug
- title: Deprecated
labels:
- deprecate
- title: Removed
labels:
- remove
- title: Security
labels:
- security
- title: Dependencies
labels:
- dependencies
- title: Others
labels:
- "*"
30 changes: 15 additions & 15 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,22 @@ jobs:
name: Small tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: make test
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: make test
e2e:
name: End-to-end tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: make setup
working-directory: e2e
- run: make start
working-directory: e2e
- run: make test
working-directory: e2e
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- run: make setup
working-directory: e2e
- run: make start
working-directory: e2e
- run: make test
working-directory: e2e
50 changes: 50 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Release
on:
push:
tags:
- 'v*'
jobs:
image:
name: Push Container Image
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- uses: docker/setup-qemu-action@v3
with:
platforms: linux/amd64
- uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ inputs.github_token }}
- name: Build necoperf-cli and necoperf-daemon image
run: |
make docker-build
- name: Push necoperf-cli and necoperf-daemon image
run: |
IMAGE_TAG=${GITHUB_REF#refs/tags/v} # Remove "v" prefix.
docker tag necoperf-cli:dev ghcr.io/cybozu-go/necoperf-cli:$IMAGE_TAG
docker push ghcr.io/cybozu-go/necoperf-cli:$IMAGE_TAG
docker tag necoperf-daemon:dev ghcr.io/cybozu-go/necoperf-daemon:$IMAGE_TAG
docker push ghcr.io/cybozu-go/necoperf-daemon:$IMAGE_TAG
release:
name: Release on GitHub
needs: image
runs-on: ubuntu-22.04
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version-file: 'go.mod'
- name: GoReleaser
uses: 'goreleaser/goreleaser-action@336e29918d653399e599bfca99fadc1d7ffbc9f7'
with:
distribution: goreleaser
version: v1.18.2
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53 changes: 53 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
builds:
- id: necoperf-cli
main: ./cmd/necoperf-cli
binary: necoperf-cli
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64
- id: necoperf-daemon
main: ./cmd/necoperf-daemon
binary: necoperf-daemon
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
goarch:
- amd64
- arm64

archives:
- id: necoperf-cli
builds: [necoperf-cli]
name_template: "necoperf-cli_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
wrap_in_directory: false
format: tar.gz
files:
- LICENSE

- id: necoperf-daemon
builds: [necoperf-daemon]
name_template: "necoperf-daemon_{{ .Tag }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
wrap_in_directory: false
format: tar.gz
files:
- LICENSE

checksum:
name_template: "checksums.txt"

changelog:
use: github-native

release:
github:
owner: zeroalphat
name: necoperf-cli
prerelease: auto
name_template: "Release {{ .Tag }}"
12 changes: 0 additions & 12 deletions CHANGELOG.md

This file was deleted.

27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ghcr.io/cybozu/golang:1.21-jammy as builder

COPY ./ .
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o necoperf-cli ./cmd/necoperf-cli
RUN CGO_ENABLED=0 go build -ldflags="-w -s" -o necoperf-daemon ./cmd/necoperf-daemon

FROM ghcr.io/flatcar/flatcar-sdk-amd64:3654.0.0 as flatcar
FROM k8s.gcr.io/pause:3.6 as pause

FROM scratch
COPY --from=flatcar /usr/bin/perf /usr/bin/sleep /usr/bin/
COPY --from=flatcar /bin/sh /bin/chown /bin/
COPY --from=flatcar /sbin/setcap /sbin/setcap

COPY --from=flatcar /usr/lib64 /usr/lib64
COPY --from=flatcar /lib64 /lib64
COPY --from=flatcar /tmp /tmp

COPY --from=pause /pause /usr/local/bin/pause
COPY --from=builder /work/necoperf-cli /usr/local/bin/necoperf-cli
COPY --from=builder /work/necoperf-daemon /usr/local/bin/necoperf-daemon

RUN setcap "cap_perfmon,cap_sys_ptrace,cap_syslog,cap_sys_admin=ep" /usr/bin/perf \
&& chown -R 1000:1000 /tmp

USER 1000:1000
ENTRYPOINT ["/usr/local/bin/necoperf-daemon", "daemon"]
22 changes: 22 additions & 0 deletions e2e/necoperf_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package e2e

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("necoperf e2e test", func() {
It("should be able to run necoperf-cli", func() {
By("executing necoperf-cli")
_, err := kubectl(nil, "exec", "necoperf-client", "--",
"necoperf-cli", "profile", "profiled-pod",
"--timeout", "100s",
"--necoperf-namespace", "necoperf")
Expect(err).NotTo(HaveOccurred())

By("checking if profiling result is created")
_, err = kubectl(nil, "cp", "necoperf-client:/tmp/profiled-pod.script", "./profiled-pod.script")
Expect(err).NotTo(HaveOccurred())
//Expect(string(out)).To(ContainSubstring("/tmp/profiled-pod.script"))
})
})

0 comments on commit 441a77e

Please sign in to comment.