Skip to content

CD

CD #19

Workflow file for this run

name: CD
on:
workflow_run:
workflows: [CI]
types: [completed]
branches: [master]
env:
OCIR_REGISTRY: mx-queretaro-1.ocir.io
IMAGE_REPOSITORY: mx-queretaro-1.ocir.io/axjlbcwfm44q/reacttodo/wx7u0/todolistapp-springboot
K8S_NAMESPACE: mtdrworkshop
K8S_DEPLOYMENT: todolistapp-springboot-deployment
K8S_CONTAINER: todolistapp-springboot
jobs:
deploy:
name: Deploy to OCI (OKE)
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
concurrency:
group: production-deploy
cancel-in-progress: false
environment: production
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- name: Log in to OCIR
uses: docker/login-action@v3
with:
registry: ${{ env.OCIR_REGISTRY }}
username: ${{ secrets.OCIR_USERNAME }}
password: ${{ secrets.OCIR_PASSWORD }}
- name: Build and Push Docker image
run: |
IMAGE_TAG="${GITHUB_SHA:0:7}"
docker build -f MtdrSpring/backend/Dockerfile -t "$IMAGE_REPOSITORY:$IMAGE_TAG" MtdrSpring/backend/
docker push "$IMAGE_REPOSITORY:$IMAGE_TAG"
- name: Set up Kubernetes config
run: |
mkdir -p ~/.kube
echo "${{ secrets.KUBECONFIG_DATA }}" | base64 -d > ~/.kube/config
chmod 600 ~/.kube/config
- name: Deploy to Kubernetes (OKE)
run: |
IMAGE_TAG="${GITHUB_SHA:0:7}"
kubectl set image deployment/"$K8S_DEPLOYMENT" "$K8S_CONTAINER"="$IMAGE_REPOSITORY":"$IMAGE_TAG" -n "$K8S_NAMESPACE"
kubectl rollout status deployment/"$K8S_DEPLOYMENT" -n "$K8S_NAMESPACE" --timeout=180s
kubectl get pods -n "$K8S_NAMESPACE"