Skip to content

Commit

Permalink
chore: configure the release job (#25)
Browse files Browse the repository at this point in the history
* chore: configure the release job

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* configure goreleaser

Signed-off-by: Leonardo Luz Almeida <[email protected]>

* remove comments

Signed-off-by: Leonardo Luz Almeida <[email protected]>

---------

Signed-off-by: Leonardo Luz Almeida <[email protected]>
  • Loading branch information
leoluz authored Oct 8, 2024
1 parent 8697604 commit ef6e779
Show file tree
Hide file tree
Showing 13 changed files with 277 additions and 47 deletions.
43 changes: 42 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,43 @@
# TODO
# see https://github.com/grpc-ecosystem/grpc-gateway/blob/main/.github/workflows/release.yml
name: release

on:
push:
tags:
- 'v*'

defaults:
run:
shell: bash

jobs:
release:
runs-on: ubuntu-20.04
if: github.repository == 'argoproj-labs/argocd-ephemeral-access'
name: Release
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # pin@v3
with:
fetch-depth: 0

- name: Setup Go
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # pin@v4
with:
go-version: 1.22

- name: Docker Login in quay.io
uses: docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # pin@v1
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@5fdedb94abba051217030cc86d4523cf3f02243d # pin@v4
with:
distribution: goreleaser
version: latest
args: release --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*.dll
*.so
*.dylib
bin/*

# Test binary, built with `go test -c`
*.test
Expand All @@ -27,3 +26,7 @@ go.work.sum
*~

/config/local
ui/extension.tar
dist/
dist-goreleaser/
bin/
115 changes: 115 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# The lines below are called `modelines`. See `:help modeline`
# yaml-language-server: $schema=https://raw.githubusercontent.com/goreleaser/goreleaser/v2.3.2/www/docs/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

project_name: argocd-ephemeral-access
version: 2

dist: bin/goreleaser

before:
hooks:
- go mod tidy
- go mod download
- make build-ui

builds:
- id: ephemeral-access
main: ./cmd
binary: ephemeral-access
env:
- CGO_ENABLED=0
flags:
- -v
goos:
- linux
- windows
- darwin
ldflags:
- -X github.com/argoproj-labs/argocd-ephemeral-access/common.version={{ .Version }}
- -X github.com/argoproj-labs/argocd-ephemeral-access/common.buildDate={{ .Date }}
- -extldflags="-static"

dockers:
- image_templates:
- quay.io/argoprojlabs/argocd-ephemeral-access:latest
- quay.io/argoprojlabs/argocd-ephemeral-access:{{ .Tag }}
dockerfile: release.Dockerfile
skip_push: "{{ .IsSnapshot }}"
build_flag_templates:
- "--pull"
- "--label=org.opencontainers.image.created={{.Date}}"
- "--label=org.opencontainers.image.title={{.ProjectName}}"
- "--label=org.opencontainers.image.revision={{.FullCommit}}"
- "--label=org.opencontainers.image.version={{.Version}}"
- "--platform=linux/amd64"

archives:
- id: binary
format: tar.gz
builds:
- "ephemeral-access"
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
- id: ui-extension
format: gz
name_template: extension.tar
meta: true
files:
- src: ui/extension.tar
strip_parent: true

checksum:
name_template: 'extension_checksums.txt'
algorithm: sha256

release:
prerelease: auto
draft: false
header: |
## argocd-ephemeral-access
{{ .Date }}
### Docker images
- quay.io/argoprojlabs/argocd-ephemeral-access:{{ .Tag }}
- quay.io/argoprojlabs/argocd-ephemeral-access:latest
footer: |
**Full Changelog**: https://github.com/argoproj-labs/argocd-ephemeral-access/compare/{{ .PreviousTag }}...{{ .Tag }}
<a href="https://argoproj.github.io/cd/"><img src="https://raw.githubusercontent.com/argoproj/argo-site/c42c87e68cea647eadc1564e9e264621442aa8cf/src/images/icon.png" width="25%" ></a>
changelog:
use:
github
sort: asc
abbrev: 0
groups: # Regex use RE2 syntax as defined here: https://github.com/google/re2/wiki/Syntax.
- title: 'Features'
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
order: 100
- title: 'Bug fixes'
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
order: 200
- title: 'Documentation'
regexp: '^.*?docs(\([[:word:]]+\))??!?:.+$'
order: 300
- title: 'Dependency updates'
regexp: '^.*?(feat|fix|chore)\(deps?.+\)!?:.+$'
order: 400
- title: 'Other work'
order: 999
filters:
exclude:
- '^test:'
- '^.*?Bump(\([[:word:]]+\))?.+$'
8 changes: 3 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ COPY pkg/ pkg/
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o controller cmd/controller/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o backend cmd/backend/main.go
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o ephemeral-access cmd/main.go

# Use distroless as minimal base image to package the controller binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/controller .
COPY --from=builder /workspace/backend .
COPY --from=builder /workspace/ephemeral-access .
USER 65532:65532

ENTRYPOINT ["/controller"]
ENTRYPOINT ["/ephemeral-access"]
32 changes: 27 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CURRENT_DIR=$(shell pwd)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.30.0

Expand Down Expand Up @@ -34,6 +35,8 @@ CONTAINER_TOOL ?= docker
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

UI_DIR=${CURRENT_DIR}/ui

.PHONY: all
all: build

Expand Down Expand Up @@ -97,16 +100,15 @@ lint-fix: golangci-lint ## Run golangci-lint linter and perform fixes

.PHONY: build
build: manifests generate fmt vet ## Build manager binary.
go build -o bin/controller cmd/controller/main.go
go build -o bin/backend cmd/backend/main.go
go build -o bin/ephemeral cmd/main.go

.PHONY: run-controller
run-controller: manifests generate fmt vet ## Run a controller from your host.
go run ./cmd/controller/main.go $(ARGS)
go run ./cmd/main.go controller $(ARGS)

.PHONY: run-backend
run-backend: fmt vet ## Run the api server backend
go run ./cmd/backend/main.go $(ARGS)
run-backend: fmt vet ## Run the api backend server
go run ./cmd/main.go backend $(ARGS)

# If you wish to build the manager image targeting other platforms you can use the --platform flag.
# (i.e. docker build --platform linux/arm64). However, you must enable docker buildKit for it.
Expand Down Expand Up @@ -185,13 +187,15 @@ CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen-$(CONTROLLER_TOOLS_VERSION)
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)
GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION)
MOCKERY ?= $(LOCALBIN)/mockery-$(MOCKERY_VERSION)
GORELEASER ?= $(LOCALBIN)/goreleaser-$(GORELEASER_VERSION)

## Tool Versions
KUSTOMIZE_VERSION ?= v5.4.1
CONTROLLER_TOOLS_VERSION ?= v0.15.0
ENVTEST_VERSION ?= release-0.18
GOLANGCI_LINT_VERSION ?= v1.57.2
MOCKERY_VERSION ?= v2.45.0
GORELEASER_VERSION ?= v2.3.2

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
Expand Down Expand Up @@ -219,10 +223,28 @@ mockery: $(MOCKERY) ## Download mockery locally if necessary.
$(MOCKERY): $(LOCALBIN)
$(call go-install-tool,$(MOCKERY),github.com/vektra/mockery/v2,$(MOCKERY_VERSION))

.PHONY: goreleaser
goreleaser: $(GORELEASER) ## Download goreleaser locally if necessary.
$(GORELEASER): $(LOCALBIN)
$(call go-install-tool,$(GORELEASER),github.com/goreleaser/goreleaser/v2,$(GORELEASER_VERSION))

.PHONY: goreleaser-build-local
goreleaser-build-local: goreleaser ## Run goreleaser build locally. Use to validate the goreleaser configuration.
$(GORELEASER) build --snapshot --clean --single-target

.PHONY: generate-mocks
generate-mocks: mockery ## Generate the mocks for the project as configured in .mockery.yaml
$(MOCKERY)

.PHONY: clean-ui
clean-ui:
find ${UI_DIR} -type f -name extension.tar -delete

.PHONY: build-ui
build-ui: clean-ui
yarn --cwd ${UI_DIR} install
yarn --cwd ${UI_DIR} build

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
Expand Down
30 changes: 19 additions & 11 deletions cmd/backend/main.go → cmd/backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,12 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package main
package backend

import (
"context"
"fmt"
"net/http"
"os"
"time"

"github.com/argoproj-labs/ephemeral-access/internal/backend"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/danielgtaylor/huma/v2/humacli"
"github.com/go-chi/chi/v5"
"github.com/sethvargo/go-envconfig"
"github.com/spf13/cobra"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
)
Expand Down Expand Up @@ -83,30 +83,37 @@ func readEnvConfigs() (*Options, error) {
return &config, nil
}

func main() {
func NewCommand() *cobra.Command {
command := cobra.Command{
Use: "backend",
Short: "Run the Ephemeral Access backend service",
Long: "The Argo CD Ephemeral Access extension requires this backend service to operate. It serves the REST API used by the UI extension.",
DisableAutoGenTag: true,
RunE: run,
}
return &command
}

func run(cmd *cobra.Command, args []string) error {
opts, err := readEnvConfigs()
if err != nil {
fmt.Fprintf(os.Stderr, "error retrieving configurations: %s\n", err)
os.Exit(1)
return fmt.Errorf("error retrieving configurations: %s", err)
}

level := log.LogLevel(opts.Log.Level)
format := log.LogFormat(opts.Log.Format)
logger, err := log.New(log.WithLevel(level), log.WithFormat(format))
if err != nil {
fmt.Fprintf(os.Stderr, "error creating logger: %s\n", err)
os.Exit(1)
return fmt.Errorf("error creating logger: %s", err)
}

restConfig, err := newRestConfig(opts.Backend.Kubeconfig, logger)
if err != nil {
logger.Error(err, "error creating new rest config")
os.Exit(1)
return fmt.Errorf("error creating new rest config: %w", err)
}
persister, err := backend.NewK8sPersister(restConfig, logger)
if err != nil {
logger.Error(err, "error creating a new k8s persister")
os.Exit(1)
return fmt.Errorf("error creating a new k8s persister: %w", err)
}
service := backend.NewDefaultService(persister, logger)
handler := backend.NewAPIHandler(service, logger)
Expand Down Expand Up @@ -156,6 +163,7 @@ func main() {
})
})
cli.Run()
return nil
}

func shutdownServer(server *http.Server) {
Expand Down
Loading

0 comments on commit ef6e779

Please sign in to comment.