Rishab49 is Building and pushing an image #36
This file contains hidden or 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: Building Docker image and pushing to DockerHub | |
| run-name: ${{ github.actor }} is Building and pushing an image | |
| on: | |
| push: | |
| branches: ['main'] | |
| paths-ignore: | |
| - '**/readme.md' | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| tag: ${{ vars.DOCKER_USERNAME}}/${{ vars.IMAGE_NAME }}:${{ steps.get-tag.outputs.id }} | |
| steps: | |
| - name: DockerHub login | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ vars.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Get tag | |
| id: get-tag | |
| run: echo "id=$(echo ${{github.sha}} | cut -c 1-7)" >> "$GITHUB_OUTPUT" | | |
| echo "tag=$id" | |
| - name: Checkout | |
| uses: actions/checkout@v2 | |
| - name: Build and push | |
| uses: docker/build-push-action@v6 | |
| with: | |
| push: true | |
| context: ./challenge9/docker | |
| file: ./challenge9/docker/Dockerfile | |
| tags: ${{ vars.DOCKER_USERNAME}}/${{ vars.IMAGE_NAME }}:${{ steps.get-tag.outputs.id }} | |
| deploy: | |
| runs-on: kub-runner | |
| needs: build | |
| steps: | |
| - name: checkout | |
| uses: actions/checkout@v4 | |
| - name: Download Kubectl binaries | |
| run: curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" | |
| - name: Install Kubectl | |
| run: sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl | |
| - name: updating config | |
| run: | | |
| IMAGE_TAG="${{ needs.build.outputs.tag }}" | |
| sed -i "s|image:.*|image: ${IMAGE_TAG}|" ./challenge9/kubernetes/deployment.yaml | |
| - name: Deploy the app to kubernetes | |
| run: | | |
| kubectl config set-cluster minikube --server=https://192.168.49.2:8443 --insecure-skip-tls-verify=true | |
| kubectl config set-credentials my-remote-access-user --token="${{ secrets.TOKEN }}" | |
| kubectl config set-context my-remote-access-context --cluster=minikube --user=my-remote-access-user --namespace=default | |
| kubectl config use-context my-remote-access-context | |
| kubectl get pods --all-namespaces | |
| kubectl config view | |
| echo "the value of TAG is ${{ needs.build.outputs.tag }}" | |
| kubectl apply -f ./challenge9/kubernetes/deployment.yaml |