Deploy SLN Release #75
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy SLN Release | |
on: | |
workflow_dispatch: | |
env: | |
IMAGE_NAME: space-launch-now-base | |
REGISTRY_NAME: registry.digitalocean.com/spacelaunchnow-registry/ | |
POETRY_HTTP_BASIC_TSD_USERNAME: ${{ secrets.PRIVATE_USERNAME }} | |
POETRY_HTTP_BASIC_TSD_PASSWORD: ${{ secrets.PRIVATE_PASSWORD }} | |
RELEASE_NAME: sln-prod-app | |
WEB_DEPLOYMENT: sln-prod-app-django-web | |
SERVICE_DEPLOYMENT: sln-prod-app-django-notification-service | |
DEPLOYMENT_NAMESPACE: sln-prod | |
VALUES: k8s/helm/values-prod.yaml | |
jobs: | |
doctl-registry: | |
name: Deploy to Container Registry | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install doctl | |
uses: digitalocean/action-doctl@v2 | |
with: | |
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
- name: Login to container registry | |
run: doctl registry login --expiry-seconds 600 | |
- name: Retag Docker Image | |
run: | | |
docker pull ${{env.REGISTRY_NAME}}${{ env.IMAGE_NAME }}:staging | |
docker tag ${{env.REGISTRY_NAME}}${{ env.IMAGE_NAME }}:staging ${{env.REGISTRY_NAME}}${{ env.IMAGE_NAME }}:latest | |
docker push ${{env.REGISTRY_NAME}}${{ env.IMAGE_NAME }}:latest | |
deploy: | |
needs: doctl-registry | |
name: Deploy to Kubernetes | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Install kubectl | |
uses: azure/setup-kubectl@v3 | |
with: | |
version: 'v1.24.0' | |
- name: Install helm | |
uses: azure/setup-helm@v3 | |
with: | |
version: 'v3.8.1' | |
- name: Create kubeconfig | |
run: | | |
mkdir ${HOME}/.kube | |
echo ${{ secrets.KUBE_CONFIG }} | base64 --decode > ${HOME}/.kube/config | |
chmod go-r ${HOME}/.kube/config | |
- name: Deploy to K8s | |
run: | | |
kubectl config use-context do-nyc1-k8s-spacelaunchnow-prod | |
export DEPLOYS=$(helm ls --all-namespaces | grep $RELEASE_NAME | wc -l) | |
if [ $DEPLOYS -eq 0 ]; | |
then | |
helm install $RELEASE_NAME k8s/helm/ --namespace=$DEPLOYMENT_NAMESPACE --values $VALUES | |
else | |
helm upgrade $RELEASE_NAME k8s/helm/ --namespace=$DEPLOYMENT_NAMESPACE --values $VALUES | |
kubectl rollout restart deploy $WEB_DEPLOYMENT --namespace=$DEPLOYMENT_NAMESPACE | |
kubectl rollout restart deploy $SERVICE_DEPLOYMENT --namespace=$DEPLOYMENT_NAMESPACE | |
fi |