Update deploy.yml #17
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: CI/CD with Kubernetes | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
with: | |
path: . # Download all repository files to the root directory | |
- name: Set up Kubernetes config | |
run: | | |
mkdir -p $HOME/.kube/ | |
cp kubeconfig.yaml $HOME/.kube/config # Replace 'kubeconfig.yaml' with the actual name of your kubeconfig file | |
cp .minikube/ca.crt $HOME/.kube/.minikube/ca.crt | |
cp .minikube/profiles/minikube/client.crt $HOME/.kube/.minikube/profiles/minikube/client.crt | |
cp .minikube/profiles/minikube/client.key $HOME/.kube/.minikube/profiles/minikube/client.key | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v1 | |
- name: Log in to DockerHub | |
run: docker login -u harisathwik -p ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push Docker image | |
run: | | |
docker buildx build --push --tag harisathwik/streamlit_app:${{ github.sha }} . | |
env: | |
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} | |
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Install ngrok | |
run: | | |
curl -LO https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip | |
unzip ngrok-stable-linux-amd64.zip | |
sudo mv ngrok /usr/local/bin | |
chmod +x /usr/local/bin/ngrok | |
- name: Expose Kubernetes service with ngrok | |
run: ngrok authtoken ${{ secrets.NGROK_AUTH_TOKEN }} && ngrok http 80 & | |
- name: Apply Kubernetes deployment | |
run: | | |
kubectl apply -f kubernetes/deployment.yaml | |
kubectl apply -f kubernetes/service.yaml |