From dbe49f3fbc81a76b0845a0a70cd3efa75e139cd5 Mon Sep 17 00:00:00 2001 From: Youngjin Jo Date: Thu, 19 Dec 2024 12:53:43 +0900 Subject: [PATCH] feat: add helm chart and Dockerfile Signed-off-by: Youngjin Jo --- .github/workflows/dispatch_release.yaml | 67 +++++++++++++++++++++++++ Dockerfile | 38 ++++++++++++++ README.md | 33 +++++++++++- deploy/helm/Chart.yaml | 4 +- deploy/helm/templates/deployment.yaml | 67 +++++++++++-------------- deploy/helm/values.yaml | 8 +-- 6 files changed, 173 insertions(+), 44 deletions(-) create mode 100644 Dockerfile diff --git a/.github/workflows/dispatch_release.yaml b/.github/workflows/dispatch_release.yaml index 23e42ea..6f1c171 100644 --- a/.github/workflows/dispatch_release.yaml +++ b/.github/workflows/dispatch_release.yaml @@ -75,3 +75,70 @@ jobs: status: ${{job.status}} fields: repo,workflow,job author_name: Github Action Slack + + docker: + needs: build + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.PAT_TOKEN }} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.CLOUDFORET_DEV_DOCKER_USERNAME }} + password: ${{ secrets.CLOUDFORET_DEV_DOCKER_PASSWORD }} + + - name: Build and push to dockerhub + uses: docker/build-push-action@v4 + with: + context: . + platforms: ${{ env.ARCH }} + push: true + tags: cloudforet/${{ github.event.repository.name }}:${{ env.VERSION }} + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-east-1 + + - name: Login to Amazon ECR + run: aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.ECR_REPO }} + + - name: Build and push to ECR + uses: docker/build-push-action@v4 + with: + context: . + platforms: ${{ env.ARCH }} + push: true + tags: ${{ secrets.ECR_REPO }}/${{ github.event.repository.name }}:${{ env.VERSION }} + + - name: Notice when job fails + if: failure() + uses: 8398a7/action-slack@v3.15.0 + with: + status: ${{job.status}} + fields: repo,workflow,job + author_name: Github Action Slack + + notification: + needs: docker + runs-on: ubuntu-latest + steps: + - name: Slack + if: always() + uses: 8398a7/action-slack@v3.15.0 + with: + status: ${{job.status}} + fields: repo,message,commit,author,action,ref,workflow,job + author_name: Github Action Slack diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a3c0db --- /dev/null +++ b/Dockerfile @@ -0,0 +1,38 @@ +# Build stage +FROM golang:1.23-alpine AS builder + +WORKDIR /app + +# Install required build tools +RUN apk add --no-cache git + +# Copy go mod files +COPY go.mod go.sum ./ +RUN go mod download + +# Copy source code +COPY . . + +# Build binary +RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o cfctl . + +# Final stage +FROM alpine:3.19 + +WORKDIR /app + +# Install CA certificates for HTTPS +RUN apk --no-cache add ca-certificates + +# Copy binary from builder +COPY --from=builder /app/cfctl . + +# Create directory for configuration +RUN mkdir -p /root/.spaceone + +# Set environment variable +ENV CFCTL_DEFAULT_ENVIRONMENT=default + +# Set entrypoint +ENTRYPOINT ["/app/cfctl"] + diff --git a/README.md b/README.md index 32b51f8..44c7f0e 100644 --- a/README.md +++ b/README.md @@ -1 +1,32 @@ -# cfctl +# cfctl - Command Line Interface for SpaceONE + +cfctl is a powerful command-line interface tool designed to interact with SpaceONE services. It provides a seamless way to manage and control your SpaceONE resources through the command line. + +## Features + +- **Dynamic Service Discovery**: Automatically discovers and interacts with available SpaceONE services +- **Multi-Environment Support**: Manages multiple environments (user/app) with easy switching +- **Secure Authentication**: Supports both user and application token-based authentication +- **Rich Output Formats**: Supports various output formats including table, yaml, json, and csv +- **Short Names**: Configurable resource aliases for faster command execution + +## Installation + +### Using Homebrew (macOS) + +```bash +brew tap cloudforet-io/tap +brew install cfctl +``` + +### Manual Installation + +Download the latest binary from [releases page](https://github.com/cloudforet-io/cfctl/releases) + +## Quick Start + +1. Initialize cfctl configuration: + +```bash +cfctl setting init +``` diff --git a/deploy/helm/Chart.yaml b/deploy/helm/Chart.yaml index a65347e..34cd426 100644 --- a/deploy/helm/Chart.yaml +++ b/deploy/helm/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: cfctl description: A cfctl chart for Kubernetes type: application -version: 0.0.1 -appVersion: 0.x.y +version: 1.0.0 +appVersion: 1.0.7 diff --git a/deploy/helm/templates/deployment.yaml b/deploy/helm/templates/deployment.yaml index c9b80ce..0c34dad 100644 --- a/deploy/helm/templates/deployment.yaml +++ b/deploy/helm/templates/deployment.yaml @@ -3,64 +3,55 @@ apiVersion: apps/v1 kind: Deployment metadata: - labels: - spaceone.service: {{ .Values.name }} name: {{ .Values.name }} - namespace: {{ .Values.global.namespace | default .Release.Namespace }} + namespace: {{ .Values.namespace | default .Release.Namespace }} + labels: + {{- include "cfctl.labels" . | nindent 4 }} spec: replicas: {{ .Values.replicas }} - revisionHistoryLimit: 3 selector: matchLabels: - spaceone.service: {{ .Values.name }} + {{- include "cfctl.selectorLabels" . | nindent 6 }} template: metadata: - annotations: - spaceone.deployment.tool: helm labels: -{{ include "spaceone.labels" . | indent 8 }} - spaceone.service: {{ .Values.name }} + {{- include "cfctl.selectorLabels" . | nindent 8 }} spec: -{{- if .Values.serviceAccountName }} - serviceAccountName: {{ .Values.serviceAccountName }} -{{- end }} - terminationGracePeriodSeconds: {{ .Values.gracePeriod }} -{{- if .Values.imagePullSecrets}} {{- with .Values.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} -{{- end}} + securityContext: + {{- toYaml .Values.securityContext | nindent 8 }} containers: - name: {{ .Values.name }} - image: {{ .Values.image.name }}:{{ .Values.image.version }} - imagePullPolicy: {{ .Values.imagePullPolicy }} -{{- if .Values.resources }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + volumeMounts: + - name: config + mountPath: {{ .Values.configPath }} + - name: data + mountPath: /data resources: - {{- toYaml .Values.resources | nindent 12 }} -{{- end }} -{{- if .Values.env }} + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.env }} env: -{{- toYaml .Values.env | nindent 12 }} -{{- end }} - volumeMounts: - - name: cfctl-data - mountPath: /root/.spaceone/ - - name: environment-conf - mountPath: /root/default.yaml - subPath: default.yaml - readOnly: true + {{- toYaml . | nindent 12 }} + {{- end }} volumes: - - name: environment-conf + - name: config configMap: - name: {{ .Values.name }}-environment-conf -{{ if .Values.pvc.storageClassName }} - - name: cfctl-data + name: {{ .Values.name }}-config + - name: data + {{- if .Values.persistence.enabled }} persistentVolumeClaim: - claimName: {{ .Release.Namespace }}-cfctl-pvc -{{ else }} - - name: cfctl-data + claimName: {{ .Values.name }}-data + {{- else }} emptyDir: {} -{{- end }} + {{- end }} {{- end }} diff --git a/deploy/helm/values.yaml b/deploy/helm/values.yaml index 01467fd..4e75015 100644 --- a/deploy/helm/values.yaml +++ b/deploy/helm/values.yaml @@ -1,10 +1,12 @@ enabled: true name: cfctl -namespace: spaceone +namespace: cloudforet + image: - name: spaceone/cfctl + name: cloudforet/cfctl version: latest -imagePullPolicy: IfNotPresent + pullPolicy: IfNotPresent + replicas: 1 resources: {}