Skip to content

feat: add workflow dispatch to docker build #730

feat: add workflow dispatch to docker build

feat: add workflow dispatch to docker build #730

Workflow file for this run

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# GitHub recommends pinning actions to a commit SHA.
# To get a newer version, you will need to update the SHA.
# You can also reference a tag or branch, but the action may change without warning.
name: Publish Docker image
on:
- push
- workflow_dispatch
jobs:
build:
name: Docker Build
runs-on: ubuntu-latest
if: ${{ github.ref != 'refs/heads/dev' && github.ref != 'refs/heads/master' }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Build
uses: docker/build-push-action@v3
with:
context: PoliNetworkBot_CSharp/
push: false
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master' }}
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Set env
if: ${{ github.ref == 'refs/heads/master' }}
run: echo "DOCKER_REPO=$(echo prod)" >> $GITHUB_ENV
- name: Set env
if: ${{ github.ref == 'refs/heads/dev' }}
run: echo "DOCKER_REPO=$(echo dev)" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v3
with:
context: PoliNetworkBot_CSharp/
push: true
tags: ghcr.io/polinetworkorg/botcsharp_${{ env.DOCKER_REPO }}:latest
# Update-K8s-Manifests:
# name: Update K8s Deployment Manifest with Image Version
# needs: push_to_registry
# runs-on: ubuntu-latest
# steps:
# - name: Get application code from repo
# uses: actions/checkout@v3
# with:
# repository: polinetworkorg/polinetwork-cd
# ssh-key: ${{ secrets.CD_DEPLOY_KEY }}
# - name: Debug
# run: |
# sudo apt install tree
# tree -L 2
# - name: Update image name in manifest file
# if: ${{ github.ref == 'refs/heads/dev' }}
# uses: azure/powershell@v1
# env:
# DOCKER_REPO: 'dev'
# STAGE_ENV: 'dev'
# with:
# inlineScript: |
# $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
# $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# azPSVersion: "latest"
# - name: Update image name in manifest file
# if: ${{ github.ref == 'refs/heads/master' }}
# env:
# DOCKER_REPO: 'prod'
# STAGE_ENV: 'prod'
# uses: azure/powershell@v1
# with:
# inlineScript: |
# $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
# $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# azPSVersion: "latest"
# - name: Update image name in manifest file
# if: ${{ github.ref == 'refs/heads/master' }}
# env:
# DOCKER_REPO: 'prod'
# STAGE_ENV: 'mat'
# uses: azure/powershell@v1
# with:
# inlineScript: |
# $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
# $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# azPSVersion: "latest"
# - name: Update image name in manifest file
# if: ${{ github.ref == 'refs/heads/dev' }}
# env:
# DOCKER_REPO: 'dev'
# STAGE_ENV: 'rooms'
# uses: azure/powershell@v1
# with:
# inlineScript: |
# $line = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml | Select-String image: | Select-Object -ExpandProperty Line
# $content = Get-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# $content | ForEach-Object {$_ -replace $line," image: polinetwork/botcsharp_${{ env.DOCKER_REPO }}:${{ github.sha }}"} | Set-Content bot-${{ env.STAGE_ENV }}/bot-deployment.yaml
# azPSVersion: "latest"
# - name: Commit changes in manifest to repo
# run: |
# git config user.name "GitHub Actions Bot"
# git config user.email ""
# git add */bot-deployment.yaml
# git commit -m "Update image version in K8s Deployment manifests file"
# git config pull.rebase false # merge
# git pull
# git push origin