# Anyone using Github actions for your deployments?

**URL:** <https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210>\
**Category:** Questions\
**Tags:** mix-releases\
**Created:** [May 3, 2020, 7:22pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210 "2020-05-03T19:22:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![polypush135](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@polypush135](https://forum.elixirforum.com/u/polypush135)\
**Post date:** [May 3, 2020, 7:22pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/1 "2020-05-03T19:22:18Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![tfwright](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/32/20299_2.png) [@tfwright](https://forum.elixirforum.com/u/tfwright)\
**Post date:** [May 3, 2020, 8:10pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/2 "2020-05-03T20:10:19Z")

</div>

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](https://forum.elixirforum.com/t/how-are-you-doing-production-deployments/2027/5). And here’s the [example GH action](https://gist.github.com/tfwright/1ee843bdc170a96a7289aea1f5e10a8d).

---

<div class="post-metadata">

**Author:** ![egze](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/egze/32/13522_2.png) [@egze](https://forum.elixirforum.com/u/egze)\
**Post date:** [May 3, 2020, 8:24pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/3 "2020-05-03T20:24:57Z")

</div>

I do something similar, but with GitLab CI.

```yaml
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/](https://mfeckie.github.io/Phoenix-In-Production-With-Systemd/)

---

<div class="post-metadata">

**Author:** ![polypush135](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@polypush135](https://forum.elixirforum.com/u/polypush135)\
**Post date:** [May 3, 2020, 8:44pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/4 "2020-05-03T20:44:05Z")

</div>

> [@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

---

<div class="post-metadata">

**Author:** ![polypush135](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@polypush135](https://forum.elixirforum.com/u/polypush135)\
**Post date:** [May 3, 2020, 8:49pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/5 "2020-05-03T20:49:40Z")

</div>

Are you using systemd to restart your app too?

> <https://gist.github.com/tfwright/b7e6a2c8be66db576404e0b9a1413a75#file-deploy-yml-L46-L50>

```elixir
    - name: Restart app
      systemd:
        name: my_app
        state: restarted
      become: yes

```

---

<div class="post-metadata">

**Author:** ![tfwright](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/tfwright/32/20299_2.png) [@tfwright](https://forum.elixirforum.com/u/tfwright)\
**Post date:** [May 3, 2020, 9:07pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/6 "2020-05-03T21:07:44Z")

</div>

Yes. The Ansible playbook will cancel the deploy if one is in progress so I haven’t had any issues with downtime between deploys.

---

<div class="post-metadata">

**Author:** ![egze](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/egze/32/13522_2.png) [@egze](https://forum.elixirforum.com/u/egze)\
**Post date:** [May 3, 2020, 10:25pm UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/7 "2020-05-03T22:25:07Z")

</div>

Haven‘t had any issues yet. I always assumed that the stop command is a synchronous call. Is it?

---

<div class="post-metadata">

**Author:** ![ericgray](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@ericgray](https://forum.elixirforum.com/u/ericgray)\
**Post date:** [May 8, 2020, 1:15am UTC](https://forum.elixirforum.com/t/anyone-using-github-actions-for-your-deployments/31210/8 "2020-05-08T01:15:16Z")

</div>

This video on youtube might help [Deploying to a server with GitHub Actions](https://www.youtube.com/watch?v=gW1TDirJ5E4&list=PLZZkJeUxu6QmO83Z1esRhp3lOeaNKZuXY&index=7&ab_channel=omgneering)
