Update deployment.yaml #25
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 | |
- name: Start Minikube | |
run: | | |
sudo apt update | |
sudo apt install conntrack | |
minikube start --driver=none | |
- 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 8501 & | |
# Replace '8501' with the port on which your Streamlit app is running | |
- name: Wait for ngrok to initialize | |
run: sleep 10 | |
- name: Get ngrok public URL | |
id: ngrok | |
run: echo "::set-output name=url::$(curl -s http://localhost:4040/api/tunnels | jq -r '.tunnels[0].public_url')" | |
- name: Update Kubernetes deployment with ngrok URL | |
run: | | |
kubectl apply -f kubernetes/deployment.yaml | |
kubectl set env deployment/streamlit-app PUBLIC_URL=$(echo ${{ steps.ngrok.outputs.url }}) | |
- name: Apply Kubernetes service | |
run: kubectl apply -f kubernetes/service.yaml |