Update docker dotnet.yml #7
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 Pipeline | |
on: [push] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up .NET | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.0.x' # Adjust the .NET version as necessary | |
- name: Restore dependencies | |
run: dotnet restore src/src.sln | |
- name: Build project | |
run: dotnet build src/src.sln --configuration Release | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/webapiargocd:latest -f src/Dockerfile . | |
- name: Log in to Docker Hub | |
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin | |
- name: Push Docker image | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/webapiargocd:latest | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout manifests repository | |
uses: actions/checkout@v4 | |
with: | |
repository: ryzam/k8s-manifests-repo | |
ssh-key: ${{ secrets.REPO_SSH_PRIVATE_KEY }} | |
- name: Update Kubernetes manifests | |
run: | | |
sed -i 's|image: .*$|image: ${{ secrets.DOCKER_USERNAME }}/webapiargocd:latest|' k8s/deployment.yaml | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add k8s/deployment.yaml | |
git commit -m "Update image to ${{ secrets.DOCKER_USERNAME }}/webapiargocd:latest" | |
git push origin main | |
- name: Print message | |
run: echo "Hello, this is a simple GitHub Action!" |