Skip to content

Commit

Permalink
Merge pull request #32 from ashraf-minhaj/refactor/rollback
Browse files Browse the repository at this point in the history
[refactor](rollback): use fetch-depth
  • Loading branch information
ashraf-minhaj authored Feb 8, 2024
2 parents c46fa2a + ce37694 commit 9c65cee
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions .github/workflows/rollback.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,42 @@ jobs:
prev_sha: ${{ steps.prev_sha.outputs.prev_sha }}
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: 'main'
# ref: 'main'
fetch-depth: '0'

- name: Get last commit SHA
id: prev_sha
run: |
git rev-parse HEAD~1
echo "prev_sha=$(git rev-parse HEAD~1)" >> "$GITHUB_OUTPUT"
rollback:
name: rollback to prev sha
needs: get_prev_sha
runs-on: ubuntu-latest
steps:
- name: Write SSH keys
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.PROD_SSH_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.PROD_SERVER_IP }} > ~/.ssh/known_hosts
# rollback:
# name: rollback to prev sha
# needs: get_prev_sha
# runs-on: ubuntu-latest
# steps:
# - name: Write SSH keys
# run: |
# install -m 600 -D /dev/null ~/.ssh/id_rsa
# echo "${{ secrets.PROD_SSH_KEY }}" > ~/.ssh/id_rsa
# ssh-keyscan -H ${{ secrets.PROD_SERVER_IP }} > ~/.ssh/known_hosts

- name: Download the .env file
run: |
echo "${{ secrets.PROD_ENV_VARS }}" > .env
# - name: Download the .env file
# run: |
# echo "${{ secrets.PROD_ENV_VARS }}" > .env

- name: provision environment variable file
run: |
echo "send the .env file to the server first"
scp .env ec2-user@${{ secrets.PROD_SERVER_IP }}:~/
ssh ec2-user@${{ secrets.PROD_SERVER_IP }} 'echo ${{ needs.get_prev_sha.outputs.prev_sha }} > rollbacksha.txt'
# - name: provision environment variable file
# run: |
# echo "send the .env file to the server first"
# scp .env ec2-user@${{ secrets.PROD_SERVER_IP }}:~/
# ssh ec2-user@${{ secrets.PROD_SERVER_IP }} 'echo ${{ needs.get_prev_sha.outputs.prev_sha }} > rollbacksha.txt'

- name: run container
run: |
ssh ec2-user@${{ secrets.PROD_SERVER_IP }} \
'echo "${{ secrets.DOCKERHUB_TOKEN }}" | sudo docker login --username=${{ secrets.DOCKERHUB_USERNAME }} --password-stdin && \
sudo docker stop ${{env.CONTAINER_NAME}} || true && \
sudo docker rm ${{env.CONTAINER_NAME}} || true && \
sudo docker run --env-file ${{env.ENV_FILE}} -d --name ${{env.CONTAINER_NAME}} -p ${{env.HOST_PORT}}:${{env.CONTAINER_PORT}} --restart always ${{ secrets.DOCKERHUB_USERNAME }}/hushhub-backend:${{ needs.get_prev_sha.outputs.prev_sha }}"'
# - name: run container
# run: |
# ssh ec2-user@${{ secrets.PROD_SERVER_IP }} \
# 'echo "${{ secrets.DOCKERHUB_TOKEN }}" | sudo docker login --username=${{ secrets.DOCKERHUB_USERNAME }} --password-stdin && \
# sudo docker stop ${{env.CONTAINER_NAME}} || true && \
# sudo docker rm ${{env.CONTAINER_NAME}} || true && \
# sudo docker run --env-file ${{env.ENV_FILE}} -d --name ${{env.CONTAINER_NAME}} -p ${{env.HOST_PORT}}:${{env.CONTAINER_PORT}} --restart always ${{ secrets.DOCKERHUB_USERNAME }}/hushhub-backend:${{ needs.get_prev_sha.outputs.prev_sha }}'

0 comments on commit 9c65cee

Please sign in to comment.