diff --git a/.github/workflows/pr-cloud-dashboard.yml b/.github/workflows/pr-cloud-dashboard.yml index f4a78851..53c19a13 100644 --- a/.github/workflows/pr-cloud-dashboard.yml +++ b/.github/workflows/pr-cloud-dashboard.yml @@ -4,7 +4,7 @@ on: pull_request: branches: - main - - managed-dashboard + - staging jobs: @@ -41,7 +41,7 @@ jobs: uses: docker/metadata-action@v3 with: images: | - docker.io/kotalco/cloud-dashboard + docker.io/kotalco/cloud-dashboard-pr tags: | type=ref,event=tag type=sha,prefix=,suffix=,format=short diff --git a/.github/workflows/publish-cloud-dashboard.yml b/.github/workflows/publish-cloud-dashboard.yml index 0a867b93..9f80f842 100644 --- a/.github/workflows/publish-cloud-dashboard.yml +++ b/.github/workflows/publish-cloud-dashboard.yml @@ -2,7 +2,9 @@ name: Build-Push dashboard on: push: - branches: [ main ] + branches: + - main + - staging tags: - 'v*' @@ -53,12 +55,28 @@ jobs: # path: cypress/videos # if-no-files-found: ignore # 'warn' or 'error' are also available, defaults to `warn` - - name: Generate Docker metadata - id: meta + + + - name: Generate Docker metadata for staging + id: meta-staging uses: docker/metadata-action@v3 + if: github.ref == 'refs/heads/staging' with: images: | - docker.io/kotalco/cloud-dashboard + docker.io/kotalco/cloud-dashboard-staging + tags: | + type=ref,event=tag + type=sha,prefix=,suffix=,format=short + flavor: | + latest=true + + - name: Generate Docker metadata for production + id: meta-production + uses: docker/metadata-action@v3 + if: github.ref == 'refs/heads/main' + with: + images: | + docker.io/kotalco/cloud-dashboard-production tags: | type=ref,event=tag type=sha,prefix=,suffix=,format=short @@ -76,11 +94,79 @@ jobs: with: username: kotalco password: ${{ secrets.DOCKERHUB_PASSWORD }} + + - name: Build and push staging + uses: docker/build-push-action@v3 + if: github.ref == 'refs/heads/staging' + with: + context: . + push: true + tags: ${{ steps.meta-staging.outputs.tags }} + labels: ${{ steps.meta-staging.outputs.labels }} - - name: Build and push + - name: Build and push production uses: docker/build-push-action@v3 + if: github.ref == 'refs/heads/main' with: context: . push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tags: ${{ steps.meta-production.outputs.tags }} + labels: ${{ steps.meta-production.outputs.labels }} + + deploy_managed-dashboard_k8s-managed-staging: + runs-on: ubuntu-latest + needs: [build] + if: ${{ (github.event_name == 'push') && (github.ref == 'refs/heads/staging') }} + steps: + - uses: actions/checkout@v3 + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV + + - name: update managed-dashboard with secrets values - staging + env: + NEXT_PUBLIC_BASE_URL: '${{ secrets.NEXT_PUBLIC_BASE_URL }}' + run: | + envsubst < ./staging-managed-dashboard.yaml | tee staging-managed-dashboard.yaml + + - name: K8s-set-context to DO managed-staging cluster + uses: azure/k8s-set-context@v1 + with: + method: kubeconfig + kubeconfig: ${{ secrets.KUBECONFIG_DO_MANAGED_STAGING }} + + - name: Deploy to the DO managed-staging cluster + uses: azure/k8s-deploy@v1 + with: + namespace: kotal + manifests: | + staging-managed-dashboard.yaml + + # deploy_managed-dashboard_k8s-managed-production: + # runs-on: ubuntu-latest + # needs: [build] + # if: ${{ (github.event_name == 'push') && (github.ref == 'refs/heads/main') }} + # steps: + # - uses: actions/checkout@v3 + + # - name: Add SHORT_SHA env property with commit short sha + # run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV + + # - name: update managed-dashboard with secrets values - production + # env: + # NEXT_PUBLIC_BASE_URL: '${{ secrets.NEXT_PUBLIC_BASE_URL }}' + # run: | + # envsubst < ./prod-managed-dashboard.yaml | tee prod-managed-dashboard.yaml + + # - name: K8s-set-context to DO managed-production cluster + # uses: azure/k8s-set-context@v1 + # with: + # method: kubeconfig + # kubeconfig: ${{ secrets.KUBECONFIG_DO_MANAGED_PRODUCTION }} + + # - name: Deploy to the DO managed-production cluster + # uses: azure/k8s-deploy@v1 + # with: + # namespace: kotal + # manifests: | + # prod-managed-dashboard.yaml \ No newline at end of file diff --git a/prod-managed-dashboard.yaml b/prod-managed-dashboard.yaml new file mode 100644 index 00000000..736aa08a --- /dev/null +++ b/prod-managed-dashboard.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "1" + generation: 1 + labels: + app.kubernetes.io/managed-by: Helm + name: kotal-dashboard + namespace: kotal +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: kotal-dashboard + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app: kotal-dashboard + spec: + containers: + - env: + - name: NEXT_PUBLIC_BASE_URL + value: /api/v1 + - name: NEXT_PUBLIC_WS_BASE_URL + value: /api/v1 + image: kotalco/cloud-dashboard-production:${SHORT_SHA} + imagePullPolicy: IfNotPresent + name: kotal-dashboard + ports: + - containerPort: 3000 + protocol: TCP + resources: + requests: + cpu: 10m + memory: 50Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 +--- +apiVersion: v1 +kind: Service +metadata: + name: kotal-dashboard +spec: + selector: + app: kotal-dashboard + ports: + - port: 3000 + targetPort: 3000 \ No newline at end of file diff --git a/staging-managed-dashboard.yaml b/staging-managed-dashboard.yaml new file mode 100644 index 00000000..17e7c332 --- /dev/null +++ b/staging-managed-dashboard.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + annotations: + deployment.kubernetes.io/revision: "1" + generation: 1 + labels: + app.kubernetes.io/managed-by: Helm + name: kotal-dashboard + namespace: kotal +spec: + progressDeadlineSeconds: 600 + replicas: 1 + revisionHistoryLimit: 10 + selector: + matchLabels: + app: kotal-dashboard + strategy: + rollingUpdate: + maxSurge: 25% + maxUnavailable: 25% + type: RollingUpdate + template: + metadata: + creationTimestamp: null + labels: + app: kotal-dashboard + spec: + containers: + - env: + - name: NEXT_PUBLIC_BASE_URL + value: /api/v1 + - name: NEXT_PUBLIC_WS_BASE_URL + value: /api/v1 + image: kotalco/cloud-dashboard-staging:${SHORT_SHA} + imagePullPolicy: IfNotPresent + name: kotal-dashboard + ports: + - containerPort: 3000 + protocol: TCP + resources: + requests: + cpu: 10m + memory: 50Mi + terminationMessagePath: /dev/termination-log + terminationMessagePolicy: File + dnsPolicy: ClusterFirst + restartPolicy: Always + schedulerName: default-scheduler + securityContext: {} + terminationGracePeriodSeconds: 30 +--- +apiVersion: v1 +kind: Service +metadata: + name: kotal-dashboard +spec: + selector: + app: kotal-dashboard + ports: + - port: 3000 + targetPort: 3000 \ No newline at end of file