From 3a6b1bb540fd74043ddd51d6af85718c7c516e88 Mon Sep 17 00:00:00 2001 From: Mahsa Soleimani Date: Sun, 4 Feb 2024 10:36:59 +0330 Subject: [PATCH] workflows (#6) Edit workflow to build images and release helm charts --- .github/workflows/ci.yaml | 91 ++++++++++++++----- .../{deploy => charts}/Chart.yaml | 2 +- .../templates/deployment.yaml | 0 .../{deploy => charts}/templates/secret.yaml | 0 .../{deploy => charts}/templates/service.yaml | 0 .../{deploy => charts}/values.yaml | 2 +- clients/proxy-client/charts/Chart.yaml | 7 ++ .../charts/templates/deployment.yaml | 46 ++++++++++ .../proxy-client/charts/templates/secret.yaml | 9 ++ .../charts/templates/service.yaml | 14 +++ clients/proxy-client/charts/values.yaml | 37 ++++++++ .../server => deployment/charts}/.helmignore | 0 .../server => deployment/charts}/Chart.yaml | 2 +- .../charts}/okd4-teh-1.yaml | 0 .../charts}/okd4-teh-2.yaml | 0 .../charts}/snappgroup-teh-1.yaml | 0 .../charts}/templates/_helpers.tpl | 0 .../charts}/templates/configmap.yaml | 0 .../charts}/templates/deployment.yaml | 0 .../charts}/templates/route.yaml | 0 .../charts}/templates/service.yaml | 0 .../charts}/templates/servicemonitor.yaml | 0 .../templates/tests/test-connection.yaml | 0 .../server => deployment/charts}/values.yaml | 0 {deployments => deployment}/teardown.sh | 0 {deployments => deployment}/tearup.sh | 0 26 files changed, 185 insertions(+), 25 deletions(-) rename clients/harbor-client/{deploy => charts}/Chart.yaml (64%) rename clients/harbor-client/{deploy => charts}/templates/deployment.yaml (100%) rename clients/harbor-client/{deploy => charts}/templates/secret.yaml (100%) rename clients/harbor-client/{deploy => charts}/templates/service.yaml (100%) rename clients/harbor-client/{deploy => charts}/values.yaml (86%) create mode 100644 clients/proxy-client/charts/Chart.yaml create mode 100644 clients/proxy-client/charts/templates/deployment.yaml create mode 100644 clients/proxy-client/charts/templates/secret.yaml create mode 100644 clients/proxy-client/charts/templates/service.yaml create mode 100644 clients/proxy-client/charts/values.yaml rename {deployments/server => deployment/charts}/.helmignore (100%) rename {deployments/server => deployment/charts}/Chart.yaml (95%) rename {deployments/server => deployment/charts}/okd4-teh-1.yaml (100%) rename {deployments/server => deployment/charts}/okd4-teh-2.yaml (100%) rename {deployments/server => deployment/charts}/snappgroup-teh-1.yaml (100%) rename {deployments/server => deployment/charts}/templates/_helpers.tpl (100%) rename {deployments/server => deployment/charts}/templates/configmap.yaml (100%) rename {deployments/server => deployment/charts}/templates/deployment.yaml (100%) rename {deployments/server => deployment/charts}/templates/route.yaml (100%) rename {deployments/server => deployment/charts}/templates/service.yaml (100%) rename {deployments/server => deployment/charts}/templates/servicemonitor.yaml (100%) rename {deployments/server => deployment/charts}/templates/tests/test-connection.yaml (100%) rename {deployments/server => deployment/charts}/values.yaml (100%) rename {deployments => deployment}/teardown.sh (100%) rename {deployments => deployment}/tearup.sh (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1aee4da..d5fa374 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -1,5 +1,5 @@ --- -name: ci +name: Lint, Test, Image Build and Chart release on: push: @@ -13,9 +13,9 @@ jobs: name: lint runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: latest args: --timeout 5m @@ -23,43 +23,90 @@ jobs: name: test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-go@v4 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: go-version: "1.20" - run: go test -v ./... -covermode=atomic -coverprofile=coverage.out - uses: codecov/codecov-action@v3 with: files: coverage.out - build: + + build-main: name: build runs-on: ubuntu-latest needs: - lint - test steps: - - uses: actions/checkout@v2 - - uses: docker/setup-qemu-action@v1 - - uses: docker/setup-buildx-action@v1 - - uses: docker/login-action@v1 + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 with: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} - - uses: docker/metadata-action@v3 - id: meta - with: - images: ghcr.io/${{ github.repository }} - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - uses: docker/build-push-action@v2 + - uses: docker/build-push-action@v5 with: file: "Dockerfile" context: . platforms: linux/amd64 push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: ghcr.io/${{ github.repository }}:${{ github.sha }} + + build-clients: + name: build + runs-on: ubuntu-latest + needs: + - lint + - test + strategy: + matrix: + dir: ["clients/proxy-client", "clients/harbor-client"] + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - uses: docker/build-push-action@v5 + with: + file: "${{ matrix.dir }}/Dockerfile" + context: ${{ matrix.dir }} + platforms: linux/amd64 + push: true + tags: ghcr.io/${{ github.repository }}/${{ matrix.dir }}:${{ github.sha }} + + release: + name: release + runs-on: ubuntu-latest + needs: + - build-main + - build-clients + strategy: + matrix: + dir: ["deploymant", "clients/proxy-client", "clients/harbor-client"] + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v3 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + with: + charts_dir: ${{ matrix.dir }} + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/clients/harbor-client/deploy/Chart.yaml b/clients/harbor-client/charts/Chart.yaml similarity index 64% rename from clients/harbor-client/deploy/Chart.yaml rename to clients/harbor-client/charts/Chart.yaml index d49ed94..e934c4c 100644 --- a/clients/harbor-client/deploy/Chart.yaml +++ b/clients/harbor-client/charts/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: snappcloud-harbor-client -description: A Helm chart for Kubernetes +description: A Helm chart for snappcloud-harbor-client type: application version: 0.1.0 diff --git a/clients/harbor-client/deploy/templates/deployment.yaml b/clients/harbor-client/charts/templates/deployment.yaml similarity index 100% rename from clients/harbor-client/deploy/templates/deployment.yaml rename to clients/harbor-client/charts/templates/deployment.yaml diff --git a/clients/harbor-client/deploy/templates/secret.yaml b/clients/harbor-client/charts/templates/secret.yaml similarity index 100% rename from clients/harbor-client/deploy/templates/secret.yaml rename to clients/harbor-client/charts/templates/secret.yaml diff --git a/clients/harbor-client/deploy/templates/service.yaml b/clients/harbor-client/charts/templates/service.yaml similarity index 100% rename from clients/harbor-client/deploy/templates/service.yaml rename to clients/harbor-client/charts/templates/service.yaml diff --git a/clients/harbor-client/deploy/values.yaml b/clients/harbor-client/charts/values.yaml similarity index 86% rename from clients/harbor-client/deploy/values.yaml rename to clients/harbor-client/charts/values.yaml index df2ea35..aee0adf 100644 --- a/clients/harbor-client/deploy/values.yaml +++ b/clients/harbor-client/charts/values.yaml @@ -1,7 +1,7 @@ replicaCount: 1 image: - repository: ghcr.io/snapp-incubator/snappcloud-status-backend + repository: ghcr.io/snapp-incubator/snappcloud-status-backend/clients/harbor-client pullPolicy: Always tag: "0.0.1" diff --git a/clients/proxy-client/charts/Chart.yaml b/clients/proxy-client/charts/Chart.yaml new file mode 100644 index 0000000..fe60ee6 --- /dev/null +++ b/clients/proxy-client/charts/Chart.yaml @@ -0,0 +1,7 @@ +apiVersion: v2 +name: snappcloud-proxy-client +description: A Helm chart for snappcloud-proxy-client + +type: application +version: 0.1.0 +appVersion: "0.0.1" diff --git a/clients/proxy-client/charts/templates/deployment.yaml b/clients/proxy-client/charts/templates/deployment.yaml new file mode 100644 index 0000000..2b4c774 --- /dev/null +++ b/clients/proxy-client/charts/templates/deployment.yaml @@ -0,0 +1,46 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "snappcloud-proxy-client.fullname" . }} + labels: + {{- include "snappcloud-proxy-client.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "snappcloud-proxy-client.selectorLabels" . | nindent 6 }} + template: + metadata: + labels: + {{- include "snappcloud-proxy-client.selectorLabels" . | nindent 8 }} + annotations: + {{- .Values.podAnnotations | toYaml | nindent 8 }} + spec: + serviceAccountName: {{ include "snappcloud-proxy-client.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 80 + protocol: TCP + env: + - name: PROXY_URL + valueFrom: + secretKeyRef: + name: {{ .Values.configSecretName }} + key: PROXY_URL + {{ .Values.nodeSelector | toYaml | nindent 8 }} + tolerations: + {{- with .Values.tolerations }} + {{- toYaml . | nindent 8 }} + {{- end }} + affinity: + {{- with .Values.affinity }} + {{- toYaml . | nindent 8 }} + {{- end }} diff --git a/clients/proxy-client/charts/templates/secret.yaml b/clients/proxy-client/charts/templates/secret.yaml new file mode 100644 index 0000000..67599b5 --- /dev/null +++ b/clients/proxy-client/charts/templates/secret.yaml @@ -0,0 +1,9 @@ +apiVersion: v1 +kind: Secret +metadata: + name: {{ .Values.configSecretName }} + labels: + {{- include "snappcloud-proxy-client.labels" . | nindent 4 }} +type: Opaque +stringData: + PROXY_URL: "The proxy address." diff --git a/clients/proxy-client/charts/templates/service.yaml b/clients/proxy-client/charts/templates/service.yaml new file mode 100644 index 0000000..337d0a1 --- /dev/null +++ b/clients/proxy-client/charts/templates/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "snappcloud-proxy-client.fullname" . }} + labels: + {{- include "snappcloud-proxy-client.labels" . | nindent 4 }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + selector: + {{- include "snappcloud-proxy-client.selectorLabels" . | nindent 4 }} diff --git a/clients/proxy-client/charts/values.yaml b/clients/proxy-client/charts/values.yaml new file mode 100644 index 0000000..a562e00 --- /dev/null +++ b/clients/proxy-client/charts/values.yaml @@ -0,0 +1,37 @@ +replicaCount: 1 + +image: + repository: ghcr.io/snapp-incubator/snappcloud-status-backend/clients/proxy-client + pullPolicy: Always + tag: "0.0.1" + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + create: false + automount: true + annotations: {} + name: "" + +service: + type: ClusterIP + port: 8080 + +resources: + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi + +autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 100 + targetCPUUtilizationPercentage: 80 + # targetMemoryUtilizationPercentage: 80 + +configSecretName: spcld-proxy-health-client diff --git a/deployments/server/.helmignore b/deployment/charts/.helmignore similarity index 100% rename from deployments/server/.helmignore rename to deployment/charts/.helmignore diff --git a/deployments/server/Chart.yaml b/deployment/charts/Chart.yaml similarity index 95% rename from deployments/server/Chart.yaml rename to deployment/charts/Chart.yaml index 2e8a4a3..9cf30ef 100644 --- a/deployments/server/Chart.yaml +++ b/deployment/charts/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: snappcloud-status-backend -description: A Helm chart for Kubernetes +description: snappcloud-status-backend Helm chart # A chart can be either an 'application' or a 'library' chart. # diff --git a/deployments/server/okd4-teh-1.yaml b/deployment/charts/okd4-teh-1.yaml similarity index 100% rename from deployments/server/okd4-teh-1.yaml rename to deployment/charts/okd4-teh-1.yaml diff --git a/deployments/server/okd4-teh-2.yaml b/deployment/charts/okd4-teh-2.yaml similarity index 100% rename from deployments/server/okd4-teh-2.yaml rename to deployment/charts/okd4-teh-2.yaml diff --git a/deployments/server/snappgroup-teh-1.yaml b/deployment/charts/snappgroup-teh-1.yaml similarity index 100% rename from deployments/server/snappgroup-teh-1.yaml rename to deployment/charts/snappgroup-teh-1.yaml diff --git a/deployments/server/templates/_helpers.tpl b/deployment/charts/templates/_helpers.tpl similarity index 100% rename from deployments/server/templates/_helpers.tpl rename to deployment/charts/templates/_helpers.tpl diff --git a/deployments/server/templates/configmap.yaml b/deployment/charts/templates/configmap.yaml similarity index 100% rename from deployments/server/templates/configmap.yaml rename to deployment/charts/templates/configmap.yaml diff --git a/deployments/server/templates/deployment.yaml b/deployment/charts/templates/deployment.yaml similarity index 100% rename from deployments/server/templates/deployment.yaml rename to deployment/charts/templates/deployment.yaml diff --git a/deployments/server/templates/route.yaml b/deployment/charts/templates/route.yaml similarity index 100% rename from deployments/server/templates/route.yaml rename to deployment/charts/templates/route.yaml diff --git a/deployments/server/templates/service.yaml b/deployment/charts/templates/service.yaml similarity index 100% rename from deployments/server/templates/service.yaml rename to deployment/charts/templates/service.yaml diff --git a/deployments/server/templates/servicemonitor.yaml b/deployment/charts/templates/servicemonitor.yaml similarity index 100% rename from deployments/server/templates/servicemonitor.yaml rename to deployment/charts/templates/servicemonitor.yaml diff --git a/deployments/server/templates/tests/test-connection.yaml b/deployment/charts/templates/tests/test-connection.yaml similarity index 100% rename from deployments/server/templates/tests/test-connection.yaml rename to deployment/charts/templates/tests/test-connection.yaml diff --git a/deployments/server/values.yaml b/deployment/charts/values.yaml similarity index 100% rename from deployments/server/values.yaml rename to deployment/charts/values.yaml diff --git a/deployments/teardown.sh b/deployment/teardown.sh similarity index 100% rename from deployments/teardown.sh rename to deployment/teardown.sh diff --git a/deployments/tearup.sh b/deployment/tearup.sh similarity index 100% rename from deployments/tearup.sh rename to deployment/tearup.sh