Skip to content

cicd

cicd #421

Workflow file for this run

name: Deploy
on: deployment
jobs:
build_job:
runs-on: ubuntu-latest
name: build dockers
steps:
- name: get environment
run: |
echo "environment is: $DEPLOY_ENVIRONMENT"
URL=''
case "$DEPLOY_ENVIRONMENT" in
*dev1*)
export URL=$DEV1_URL
export KUBE_CONFIG_DATA=$DEV1_KUBE_CONFIG_DATA
;;
*test*)
export URL=$TEST_URL
export KUBE_CONFIG_DATA=$TEST_KUBE_CONFIG_DATA
;;
*cicd*)
export URL=$CICD_URL
export KUBE_CONFIG_DATA=$CICD_KUBE_CONFIG_DATA
;;
**)
echo "unknown environment. defaulting to cicd"
export URL=$CICD_URL
export KUBE_CONFIG_DATA=$CICD_KUBE_CONFIG_DATA
;;
esac
echo URL=$URL >> $GITHUB_ENV
# echo KUBE_CONFIG_DATA=$KUBE_CONFIG_DATA >> $GITHUB_ENV
echo "$KUBE_CONFIG_DATA" | base64 --decode > /tmp/config
echo KUBECONFIG=/tmp/config >> $GITHUB_ENV
env:
DEPLOY_ENVIRONMENT: '${{ github.event.deployment.environment }}'
CICD_URL: ${{ secrets.CICD_URL }}
CICD_KUBE_CONFIG_DATA: ${{ secrets.CICD_KUBECONFIG }}
DEV1_URL: ${{ secrets.DEV1_URL }}
DEV1_KUBE_CONFIG_DATA: ${{ secrets.DEV1_KUBECONFIG }}
TEST_URL: ${{ secrets.TEST_KUBERNETES_MASTER_IP }}
TEST_KUBE_CONFIG_DATA: ${{ secrets.TEST_KUBECONFIG }}
- name: set deployment status to in progress
id: start_deployment
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ github.event.deployment.id }}
environment: ${{ github.event.deployment.environment }}
environment_url: https://${{ env.URL }}/hkube/dashboard-${{ github.event.deployment.payload.prName }}/
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
state: in_progress
mediaType: '{"previews": ["flash", "ant-man"]}'
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: Checkout
uses: actions/checkout@v2
- uses: actions/setup-node@v2-beta
with:
node-version: '22'
- name: Docker login
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USER }} --password-stdin
# - name: create kubeconfig
# run: |
# env
# echo "$KUBE_CONFIG_DATA" | base64 --decode > /tmp/config
# echo KUBECONFIG=/tmp/config >> $GITHUB_ENV
- name: verify kubectl
run: kubectl cluster-info
- run: npm ci
- name: build
run: PRIVATE_REGISTRY=docker.io/hkube npm run build
env:
TRAVIS_PULL_REQUEST: 'true'
PR_NAME: ${{ github.event.deployment.payload.prName }}
- name: deploy
run: ./scripts/deploy-staging.sh
env:
PR_NAME: ${{ github.event.deployment.payload.prName }}
- name: set deployment status to success
id: successful_deployment
uses: octokit/request-action@v2.x
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ github.event.deployment.id }}
environment: ${{ github.event.deployment.environment }}
environment_url: https://${{ env.URL }}/hkube/dashboard-${{ github.event.deployment.payload.prName }}/
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: success
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'
- name: set deployment status to failure
id: failed_deployment
uses: octokit/request-action@v2.x
if: failure()
with:
route: POST /repos/:repository/deployments/:deployment/statuses
repository: ${{ github.repository }}
deployment: ${{ github.event.deployment.id }}
environment: ${{ github.event.deployment.environment }}
environment_url: https://${{ env.URL }}/hkube/dashboard-${{ github.event.deployment.payload.prName }}/
log_url: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
mediaType: '{"previews": ["ant-man"]}'
state: failure
env:
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}'