Rishab49 is Building and pushing an image #17
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'] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| 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: ./challenge8/docker | |
| file: ./challenge8/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.id }}" | | |
| sed -i "s|image:.*|image: ${IMAGE_TAG}|" ./challenge9/kubernetes/deployment.yaml | |
| - name: Deploy the app to kubernetes | |
| run: kubectl apply -f ./challenge9/kubernetes/deployment.yaml |