|
9 | 9 |
|
10 | 10 | name: Publish Docker image |
11 | 11 |
|
12 | | -on: |
13 | | - push |
| 12 | +on: push |
14 | 13 |
|
15 | 14 | jobs: |
16 | | - build: |
17 | | - name: Docker Build |
18 | | - runs-on: ubuntu-latest |
19 | | - if: ${{ github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/master' }} |
20 | | - steps: |
21 | | - - name: Check out the repo |
22 | | - uses: actions/checkout@v3 |
23 | | - |
24 | | - - name: Build |
25 | | - uses: docker/build-push-action@v3 |
26 | | - with: |
27 | | - context: PoliNetworkBot_CSharp/ |
28 | | - push: false |
29 | | - |
30 | | - push_to_registry: |
31 | | - name: Push Docker image to Docker Hub |
32 | | - runs-on: ubuntu-latest |
33 | | - if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' }} |
34 | | - steps: |
35 | | - - name: Check out the repo |
36 | | - uses: actions/checkout@v3 |
37 | | - |
38 | | - - name: Log in to Docker Hub |
39 | | - uses: docker/login-action@v2 |
40 | | - with: |
41 | | - username: ${{ secrets.DOCKER_USERNAME }} |
42 | | - password: ${{ secrets.DOCKER_PASSWORD }} |
43 | | - |
44 | | - - name: Extract branch name |
45 | | - shell: bash |
46 | | - run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" |
47 | | - id: extract_branch |
48 | | - |
49 | | - - name: Set env |
50 | | - if: ${{ github.ref == 'refs/heads/master' }} |
51 | | - run: echo "DOCKER_REPO=$(echo prod)" >> $GITHUB_ENV |
52 | | - |
53 | | - - name: Set env |
54 | | - if: ${{ github.ref == 'refs/heads/dev' }} |
55 | | - run: echo "DOCKER_REPO=$(echo dev)" >> $GITHUB_ENV |
56 | | - |
57 | | - - name: Build and push Docker image |
58 | | - uses: docker/build-push-action@v3 |
59 | | - with: |
60 | | - context: PoliNetworkBot_CSharp/ |
61 | | - push: true |
62 | | - tags: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }} |
63 | | - |
64 | | - Update-K8s-Manifests: |
65 | | - name: Update K8s Deployment Manifest with Image Version |
66 | | - needs: push_to_registry |
67 | | - runs-on: ubuntu-latest |
68 | | - steps: |
69 | | - - name: Get application code from repo |
70 | | - uses: actions/checkout@v3 |
71 | | - with: |
72 | | - repository: polinetworkorg/polinetwork-cd |
73 | | - ssh-key: ${{ secrets.CD_DEPLOY_KEY }} |
74 | | - |
75 | | - - name: Debug |
76 | | - run: | |
77 | | - sudo apt install tree |
78 | | - tree -L 2 |
79 | | -
|
80 | | - - name: Update image name in manifest file |
81 | | - if: ${{ github.ref == 'refs/heads/dev' }} |
82 | | - uses: azure/powershell@v1 |
83 | | - env: |
84 | | - DOCKER_REPO: 'dev' |
85 | | - STAGE_ENV: 'dev' |
86 | | - with: |
87 | | - inlineScript: | |
88 | | - $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
89 | | - $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
90 | | - $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
91 | | - azPSVersion: "latest" |
92 | | - |
93 | | - - name: Update image name in manifest file |
94 | | - if: ${{ github.ref == 'refs/heads/master' }} |
95 | | - env: |
96 | | - DOCKER_REPO: 'prod' |
97 | | - STAGE_ENV: 'prod' |
98 | | - uses: azure/powershell@v1 |
99 | | - with: |
100 | | - inlineScript: | |
101 | | - $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
102 | | - $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
103 | | - $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
104 | | - azPSVersion: "latest" |
105 | | - |
106 | | - - name: Update image name in manifest file |
107 | | - if: ${{ github.ref == 'refs/heads/master' }} |
108 | | - env: |
109 | | - DOCKER_REPO: 'prod' |
110 | | - STAGE_ENV: 'mat' |
111 | | - uses: azure/powershell@v1 |
112 | | - with: |
113 | | - inlineScript: | |
114 | | - $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
115 | | - $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
116 | | - $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
117 | | - azPSVersion: "latest" |
118 | | - |
119 | | - - name: Update image name in manifest file |
120 | | - if: ${{ github.ref == 'refs/heads/dev' }} |
121 | | - env: |
122 | | - DOCKER_REPO: 'dev' |
123 | | - STAGE_ENV: 'rooms' |
124 | | - uses: azure/powershell@v1 |
125 | | - with: |
126 | | - inlineScript: | |
127 | | - $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
128 | | - $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
129 | | - $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
130 | | - azPSVersion: "latest" |
131 | | - |
132 | | - - name: Commit changes in manifest to repo |
133 | | - run: | |
134 | | - git config user.name "GitHub Actions Bot" |
135 | | - git config user.email "" |
136 | | - git add */bot-deployment.yaml |
137 | | - git commit -m "Update image version in K8s Deployment manifests file" |
138 | | - git config pull.rebase false # merge |
139 | | - git pull |
140 | | - git push origin |
| 15 | + build: |
| 16 | + name: Docker Build |
| 17 | + runs-on: ubuntu-latest |
| 18 | + if: ${{ github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/master' }} |
| 19 | + steps: |
| 20 | + - name: Check out the repo |
| 21 | + uses: actions/checkout@v3 |
| 22 | + |
| 23 | + - name: Build |
| 24 | + uses: docker/build-push-action@v3 |
| 25 | + with: |
| 26 | + context: PoliNetworkBot_CSharp/ |
| 27 | + push: false |
| 28 | + |
| 29 | + push_to_registry: |
| 30 | + name: Push Docker image to Docker Hub |
| 31 | + runs-on: ubuntu-latest |
| 32 | + if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' }} |
| 33 | + steps: |
| 34 | + - name: Check out the repo |
| 35 | + uses: actions/checkout@v3 |
| 36 | + |
| 37 | + - name: Log in to Docker Hub |
| 38 | + uses: docker/login-action@v2 |
| 39 | + with: |
| 40 | + registry: ghcr.io |
| 41 | + username: ${{ github.actor }} |
| 42 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 43 | + |
| 44 | + - name: Extract branch name |
| 45 | + shell: bash |
| 46 | + run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})" |
| 47 | + id: extract_branch |
| 48 | + |
| 49 | + - name: Set env |
| 50 | + if: ${{ github.ref == 'refs/heads/master' }} |
| 51 | + run: echo "DOCKER_REPO=$(echo prod)" >> $GITHUB_ENV |
| 52 | + |
| 53 | + - name: Set env |
| 54 | + if: ${{ github.ref == 'refs/heads/dev' }} |
| 55 | + run: echo "DOCKER_REPO=$(echo dev)" >> $GITHUB_ENV |
| 56 | + |
| 57 | + - name: Build and push Docker image |
| 58 | + uses: docker/build-push-action@v3 |
| 59 | + with: |
| 60 | + context: PoliNetworkBot_CSharp/ |
| 61 | + push: true |
| 62 | + tags: ghcr.io/polinetworkorg/botcsharp_${{ env.DOCKER_REPO }}:latest |
| 63 | + |
| 64 | + # Update-K8s-Manifests: |
| 65 | + # name: Update K8s Deployment Manifest with Image Version |
| 66 | + # needs: push_to_registry |
| 67 | + # runs-on: ubuntu-latest |
| 68 | + # steps: |
| 69 | + # - name: Get application code from repo |
| 70 | + # uses: actions/checkout@v3 |
| 71 | + # with: |
| 72 | + # repository: polinetworkorg/polinetwork-cd |
| 73 | + # ssh-key: ${{ secrets.CD_DEPLOY_KEY }} |
| 74 | + |
| 75 | + # - name: Debug |
| 76 | + # run: | |
| 77 | + # sudo apt install tree |
| 78 | + # tree -L 2 |
| 79 | + |
| 80 | + # - name: Update image name in manifest file |
| 81 | + # if: ${{ github.ref == 'refs/heads/dev' }} |
| 82 | + # uses: azure/powershell@v1 |
| 83 | + # env: |
| 84 | + # DOCKER_REPO: 'dev' |
| 85 | + # STAGE_ENV: 'dev' |
| 86 | + # with: |
| 87 | + # inlineScript: | |
| 88 | + # $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
| 89 | + # $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 90 | + # $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 91 | + # azPSVersion: "latest" |
| 92 | + |
| 93 | + # - name: Update image name in manifest file |
| 94 | + # if: ${{ github.ref == 'refs/heads/master' }} |
| 95 | + # env: |
| 96 | + # DOCKER_REPO: 'prod' |
| 97 | + # STAGE_ENV: 'prod' |
| 98 | + # uses: azure/powershell@v1 |
| 99 | + # with: |
| 100 | + # inlineScript: | |
| 101 | + # $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
| 102 | + # $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 103 | + # $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 104 | + # azPSVersion: "latest" |
| 105 | + |
| 106 | + # - name: Update image name in manifest file |
| 107 | + # if: ${{ github.ref == 'refs/heads/master' }} |
| 108 | + # env: |
| 109 | + # DOCKER_REPO: 'prod' |
| 110 | + # STAGE_ENV: 'mat' |
| 111 | + # uses: azure/powershell@v1 |
| 112 | + # with: |
| 113 | + # inlineScript: | |
| 114 | + # $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
| 115 | + # $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 116 | + # $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 117 | + # azPSVersion: "latest" |
| 118 | + |
| 119 | + # - name: Update image name in manifest file |
| 120 | + # if: ${{ github.ref == 'refs/heads/dev' }} |
| 121 | + # env: |
| 122 | + # DOCKER_REPO: 'dev' |
| 123 | + # STAGE_ENV: 'rooms' |
| 124 | + # uses: azure/powershell@v1 |
| 125 | + # with: |
| 126 | + # inlineScript: | |
| 127 | + # $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line |
| 128 | + # $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 129 | + # $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml |
| 130 | + # azPSVersion: "latest" |
| 131 | + |
| 132 | + # - name: Commit changes in manifest to repo |
| 133 | + # run: | |
| 134 | + # git config user.name "GitHub Actions Bot" |
| 135 | + # git config user.email "" |
| 136 | + # git add */bot-deployment.yaml |
| 137 | + # git commit -m "Update image version in K8s Deployment manifests file" |
| 138 | + # git config pull.rebase false # merge |
| 139 | + # git pull |
| 140 | + # git push origin |
0 commit comments