By default deploy(1)
will look for ./deploy.conf, consisting of one or more environments, [stage]
, [production]
, etc, followed by directives.
[stage]
key /path/to/some.pem
user deployer
host n.n.n.n
port nn
repo git@github.com:test/test.git
path /var/www/myapp.com
ref origin/master
post-deploy /var/www/myapp.com/update.sh
Path to identity file used by ssh -i
.
key /path/to/some.pem
This is a basic demo showing how to deploy a project from Git to a running Docker container.
$ git clone https://github.com/ionpantalon/docker_deployment.git
Get the version of Docker
$ docker version
Let's start by creating a Docker image from the Dockerfile. If you are not familiar with Docker or never used it before have a look at Docker docs
$ docker build -t 'my-image-name' .
Test if the image was created using
$ docker images
Create a container using my-image-name
$ docker run -dt --name dep_test my-image-name
- -t,--tty Allocate a pseudo-TTY
- -d, --detach Run container in background and print container ID
To check if the container is running and to get information about it like the name, size,etc, 'docker ps' can be used
$ docker ps or docker ps -a
Check if SSH is installed
$ ssh -V
Check the .ssh dir
$ ls -a ~/.ssh
To generate new keys
$ ssh-keygen
To start the agent
$ ssh-agent /bin/bash
Next let's load the new generated keys on the ssh-agent
$ ssh-add ~/.ssh/id_rsa
Check if it was succesfully loaded
$ ssh-add -l
Next copy the content of .ssh/id_rsa.pub and paste into SSH Key field on your git account
To test it clone the project using
$ git clone git@bitbucket.org :< accountname>/<reponame>.git
Edit the variables to the appropiate paths and settings to match your project configuration
To deploy you can run it manually using
$ sudo ./deploy.sh
Or you can configure a web hook to deploy on certain events. When one of those events is triggered, a HTTP POST payload to the webhook's configured URL is sent. For more information about how to set up a web hook check Git webhooks
To test if the project was succesfully deployed login on the container and check the deployment path
$ docker exec -ti dep_test /bin/bash
- -t, --tty Allocate a pseudo-TTY
- -i, --interactive Keep STDIN open even if not attached