Simple github action to run docker-compose on remote host.
This action packs contents of the action workspace into archive.
Logs into remote host via ssh. Unpacks the workspace there and runs
docker-compose up -d
command.
Comparing to other actions with similar behavior this one does not use any
unknown docker-images. It is entirely built from Dockerfile on top of
alpine:3.8
.
ssh_private_key
- Base64 encoded Private SSH key used for logging into remote system. Please, keep your key securely in github secrets.ssh_host
- Remote host name.ssh_port
- Remote port for SSH connection. Default is 22.ssh_user
- Remote user which should have access to docker.docker_compose_prefix
- Project name passed to compose. Each docker container will have this prefix in name.docker_compose_file
- Path to the docker-compose file in the repository. Default is 'docker-compose.yml'
Let's say we have a repo with single docker-compose file in it and remote ubuntu based server with docker and docker-compose installed.
- Generate key pair, do not use a password here.
ssh-keygen -t ed25519 -f deploy_key
- Create a user which will deploy containers for you on the remote server, do not set password for this user:
ssh example.com
$ sudo useradd -m -b /var/lib -G docker docker-deploy
- Allow to log into that user with the key you generated on the step one.
scp deploy_key.pub example.com:~
ssh example.com
$ sudo mkdir /var/lib/docker-deploy/.ssh
$ sudo chown docker-deploy:docker-deploy /var/lib/docker-deploy/.ssh
$ sudo install -o docker-deploy -g docker-deploy -m 0600 deploy_key.pub /var/lib/docker-deploy/.ssh/authorized_keys
$ sudo chmod 0500 /var/lib/deploy/.ssh
$ rm deploy_key.pub
- Test that key works.
ssh -i deploy_key docker-deploy@example.com
-
Add private key and user name into secrets for the repository. Let's say that names of the secrets are
EXAMPLE_COM_SSH_PRIVATE_KEY
andEXAMPLE_COM_SSH_USER
. -
Remove your local copy of the ssh key:
rm deploy_key
- Setup a github-actions workflow (e.g.
.github/workflows/deploy.yml
):
name: Deploy
on:
push:
branches: [ main ]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ameerhmzx/action-deploy-compose@v1
name: Docker-Compose Remote Deployment
with:
ssh_host: example.com
ssh_private_key: ${{ secrets.EXAMPLE_COM_SSH_PRIVATE_KEY }}
ssh_user: ${{ secrets.EXAMPLE_COM_SSH_USER }}
docker_compose_prefix: example_com
- You're all set!