Brainstorming Deployment Workflow

Hey Community,

I am trying to create a workflow to automate my deployment process that I would normally do locally on my machine via terminal. Currently I have an EC2 server set up with a remote repo, with a post receive hook that I push my latests changes to from my local machine. This is workings great however It not Ideal for the rest of my team.

I’d like to do this with a github action workflow. So whenever a pull request from the master into staging is merged. The action will run and deploy the staging branch to my EC2 server, by pushing this branch to my remote repo on the server.

Problem: I’ve tried to do this in a workflow to discover that the staging branch on github as different hashes than my staging branch locally and will not push the some refs. Also --force push  will result in (shallow update not allowed).

I am new to the devOps world and development and would like some advice on how I could make this work or maybe another strategy.

@kidcaulfield ,

Do you mean when you push some changes from local repository to the GitHub repository, trigger a workflow to sync these new changes to the repository hosted on the EC2?
If so, you can try the following steps in your workflow:

jobs:
  sync_changes:
    name: Sync changes
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Sync changes to EC2
        run: |
          git remote rm github
          git remote add bitbucket <link of the EC2 repository>
          git checkout <branch name>
          git push

@brightran

Hey thanks for the suggestion, however I’ve tried something similar. There was a few problems with it. One was i have already been pushing to this repo from my local. And the children commit hashes from the parent branch on github do not sync up with the hashes locally. Secondy if i try to force push I get an error pack saying ! [remote rejected] staging -\> staging (shallow update not allowed)

here’s my code.

name: CI
on:
  push:
    branches:
     - staging

jobs:
  deploy-staging:
    runs-on: ubuntu-latest
    env:
       SSH_KEY: ${{ secrets.SSH_KEY }}
    steps:
    - uses: actions/checkout@v2
    - name: Deploy api to staging
      env:
        GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
        REMOTE_REPO: ${{ secrets.REPO }}
      run: |
        echo Deploying API to Staging
        eval `ssh-agent -s`
        ssh-add - <<< "${SSH_KEY}"
        git remote add staging "${REMOTE_REPO}"
        git push staging

Hey figured out a working solution to what i set out to do. This is an easy way to deploy to a private remote repo. It may not be the best deploytment strategy but its a quick what to get Continuous integration running Thanks again got the help @brightran and here was the final solution.

name: CI-Deploy-Staging
on:
  push:
    branches:
     - staging

jobs:
  deploy-staging:
    runs-on: ubuntu-latest
    env:
       SSH_KEY: ${{ secrets.SSH_KEY }}
    steps:
    - uses: actions/checkout@v2
    - name: Deploy api to staging
      env:
        GIT_SSH_COMMAND: "ssh -o StrictHostKeyChecking=no"
        REMOTE_REPO: ${{ secrets.STAGING_REPO }}
      run: |
        echo Deploying API to Staging
        eval `ssh-agent -s`
        ssh-add - <<< "${SSH_KEY}"
        git remote rm origin
        git remote add origin git@github:private.git
        git fetch --unshallow origin
        echo ==============last 10 commits==================
        git log -n 10
        echo ===============================================
        git remote add staging "${REMOTE_REPO}"
        git push staging -f

@kidcaulfield ,

Glad that the the problem has been solved.

And thanks for sharing your solution, I think this will help more people who have the similar questions.

Have a nice day.