One-Click Deployments for Small Projects
Tags: blog, deploy, devops, deployment
Published: 2020-11-29 09:20:19

---
title: One-Click Deployments for Small Projects
published: true
date: 2020-11-08 16:00:00 UTC
tags: Blog,Deploy,DevOps,deployment
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/4vy5gb7djppeujog9vff.png 
canonical_url: https://www.justice.sh/blog/devops/one-click-deployments-for-small-projects/
---

When we think of DevOps and deployments, we usually think about big fancy automated deployment pipelines.  
Although I love deployment pipelines, others have written great articles and tutorials.

If you are looking to expand our Travis CI build server from [Getting Started with Build Servers](https://www.justice.sh/blog/devops/devops-ep-4-build-servers/), its super easy to implement with the Travis CI documentation at [https://docs.travis-ci.com/user/deployment/](https://docs.travis-ci.com/user/deployment/).

Instead I want to show you how I deploy small projects with a one-click deployment script.  
Before continuing, make sure you know the PowerShell basics from my [Cross-Platform Command Line](https://www.justice.sh/blog/devops/command-line-basics/) article.

## Writing a Deployment Script

For this example, we will deploy a WordPress theme. It’s a common use-case and does not require you to know **anything** about WordPress.

As for all small projects, we will follow four simple steps to help us determine how we will deploy via script.

### Step 1: What do we need?

A WordPress theme is a simple directory with php, css and javascript files.  
If you want to see an example, have a look at the [TwentySeventeen sample theme](https://core.trac.wordpress.org/browser/trunk/src/wp-content/themes/twentyseventeen).

As a wordpress theme only consists of this directory, we do not have any builds to upload. We simply upload our entire theme directory.

For this example, we will call this folder `my-custom-theme`.

### Step 2: Where do we need it?

Now that we have a wordpress theme, where must we deploy it to?  
For this example, we will assume that we have two servers:

- `dev.justice.sh` – a private server for testing new code
- `justice.sh` – a public server hosting your website

WordPress themes are installed by uploading them into the `wp-content/themes` directory. If you wish to learn more on the wordpress folder structure, [this article](https://www.wpdownloadmanager.com/basic-guide-to-wordpress-file-and-directory-structure/) gives a great overview.

So let’s say our target path is `/var/www/wordpress/wp-content/themes`.

### Step 3: How do we transfer it?

While there are many ways to upload our theme, SSH and FTP are the most popular ones.

Because setting up FTP via script is [a little more work](https://www.thomasmaurer.ch/2010/11/powershell-ftp-upload-and-download/), I prefer using SSH.  
If you are using Windows 10, you must [enable the OpenSSH client first](https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse).

First of all, make sure that you can access your server via ssh.  
I recommend using ssh keys instead of username/password. See [this article using windows + powershell](https://www.chrisjhart.com/Windows-10-ssh-copy-id/).   
If you are on mac or Linux, you can simply use `ssh-keygen` and `ssh-copy-id`.

### Step 4: Script it!

With the above information, we can now write our two scripts.  
Be sure to replace USERNAME with your own username:

#### deploy-dev.sh

```
#!/bin/sh

# Copy the directory 'my-custom-theme' to our target server via ssh.
scp -r my-custom-theme USERNAME@dev.justice.sh:/var/www/wordpress/wp-content/themes
```

#### deploy-prod.sh

```
#!/bin/sh

# Copy the directory 'my-custom-theme' to our target server via ssh.
scp -r my-custom-theme USERNAME@justice.sh:/var/www/wordpress/wp-content/themes
```

## Conclusion

With the above two scripts, you can simply run `./deploy-dev.ps1` or `./deploy-prod.ps1` to deploy to DEV or PROD servers.  
I like to commit my deployment scripts in git, so I always have them together with my projects.

And so this part of the [Getting Started with DevOps](https://www.justice.sh/blog/devops/getting-started-with-devops/) series comes to a close.  
If you have any questions or feedback, you can reach me on [Twitter](https://twitter.com/JusticeDev) or on the [BrutalHack Discord Server](https://discordapp.com/invite/4FmEwGp).

The post [One-Click Deployments for Small Projects](https://www.justice.sh/blog/devops/one-click-deployments-for-small-projects/) appeared first on [justice.sh](https://www.justice.sh).