I have my elixir project up and have manually deployed it to digital ocean. Currently I every time I make changes, I have to manually go to my server and perform a git pull etc.How can i setup automated deployment such that every time I commit, the necessary mix release
procedure should be done?:
currently i have setup my gitlab ci/cd configuration as follows:
image: elixir:1.12.2
stages:
- build
- test
- deploy
variables:
MIX_ENV: "prod"
SSH_USER: "root"
SSH_HOST: "myapp.com"
APP_PATH: "/var/www/path_to_my_app"
before_script:
- apt-get update && apt-get install -y openssh-client
build:
stage: build
script:
- mix deps.get
- mix compile
test:
stage: test
script:
- mix test
deploy:
stage: deploy
script:
- echo "$SSH_PRIVATE_KEY" | tr -d '\r' > ~/.ssh/id_rsa
- chmod 600 ~/.ssh/id_rsa
- ssh -o "StrictHostKeyChecking=no" $SSH_USER@$SSH_HOST "cd $APP_PATH && git pull && source .env && _build/prod/rel/my_app/bin/my_app stop && mix ecto.migrate && source .env && mix deps.get --only prod && MIX_ENV=prod mix compile && MIX_ENV=prod mix assets.deploy && mix phx.gen.release && MIX_ENV=prod mix release --overwrite && _build/prod/rel/my_app/bin/my_app daemon"
environment:
name: production
url: http://myapp.com
only:
- main