Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor](rollback): use fetch-depth #32

Merged
merged 6 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }}'
Loading