I’m not much of a shell scripter and was hoping to see if anyone else is deploying via github actions and if they are willing to share what that looks like.
My current issue is that I believe I’m trying to start the new release before the prior stop has completed and it ends up failing to start the new release.
https://github.com/MorphicPro/morphic.pro/blob/master/.github/workflows/CD.yml#L142
Should I have some type of condition here that checks for a PID?
Not a direct solution to your problem, but I am using Ansible in conjunction with Github actions and it has worked great. Ansible will handle a lot of the heavy lifting for you, and it’s DSL is very close to GH actions anyway. I posted the Ansible playbook here . And here’s the example GH action .
egze
May 3, 2020, 8:24pm
3
I do something similar, but with GitLab CI.
script:
- ssh-add <(echo "$PRODUCTION_PRIVATE_KEY")
- VERSION_FOLDER=`date +%F_%T`
- scp -P$PRODUCTION_SSH_PORT -r release.tar.gz $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST:/var/www/apps/myapp
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "mkdir -p /var/www/apps/myapp/versions/$VERSION_FOLDER"
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "sudo /bin/systemctl stop myapp.service"
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "tar -xf /var/www/apps/myapp/release.tar.gz -C /var/www/apps/myapp/versions/$VERSION_FOLDER"
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "ln -sfn /var/www/apps/myapp/versions/$VERSION_FOLDER /var/www/apps/myapp/current"
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "sudo /bin/systemctl start myapp.service"
- ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST "ls -dt /var/www/apps/myapp/versions/* | tail -n +5 | xargs rm -rf"
I start/stop services with systemd. Took the config here, I think https://mfeckie.github.io/Phoenix-In-Production-With-Systemd/
egze:
ssh -p$PRODUCTION_SSH_PORT $PRODUCTION_DEPLOY_USER@$PRODUCTION_HOST “sudo /bin/systemctl stop myapp.service”
I wonder if you could have the same issue I’m seeing where the shutdown is not fast enough before the new start tries
Are you using systemd to restart your app too?
- name: Restart app
systemd:
name: my_app
state: restarted
become: yes
Yes. The Ansible playbook will cancel the deploy if one is in progress so I haven’t had any issues with downtime between deploys.
egze
May 3, 2020, 10:25pm
7
Haven‘t had any issues yet. I always assumed that the stop command is a synchronous call. Is it?