|
1 | 1 | # Bitbucket Pipelines
|
2 | 2 |
|
3 |
| -This article is currently work in progress! |
| 3 | +## Configuring deployment environments |
| 4 | + |
| 5 | +To start using Bitbucket Pipelines, we need to prepare the environments we want to deploy to. |
| 6 | + |
| 7 | +For example, these environments can be: |
| 8 | + |
| 9 | +- production |
| 10 | +- acceptance (or staging) |
| 11 | +- test |
| 12 | + |
| 13 | +### Configuring the production environment |
| 14 | + |
| 15 | +Hypernode Deploy will need a pair of SSH keys for authentication to the server. |
| 16 | + |
| 17 | +First, we generate an SSH keypair on the production server, copy the public key to the `~/.ssh/authorized_keys` file |
| 18 | +and encode the private key with base64. We'll use this base64-encoded private key later on. |
| 19 | + |
| 20 | +```console |
| 21 | +app@abc-example-magweb-cmbl:~$ ssh-keygen -t ed25519 -C bb-pipelines-deploy -f bb-pipelines-deploy -q -P "" |
| 22 | +app@abc-example-magweb-cmbl:~$ cat bb-pipelines-deploy.pub >> ~/.ssh/authorized_keys |
| 23 | +app@abc-example-magweb-cmbl:~$ cat bb-pipelines-deploy | base64 -w0 # encode the private key with base64 |
| 24 | +LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtV... |
| 25 | +``` |
| 26 | + |
| 27 | +Now go to your Bitbucket repository and enable Bitbucket pipelines being going to **Repository settings -> Pipelines -> Settings** and turn on **Enable Pipelines**. |
| 28 | + |
| 29 | +Now go to **Repository settings -> Pipelines -> Repository variables**. |
| 30 | + |
| 31 | +1. Create a new variable with name `SSH_PRIVATE_KEY`, mark this variable as Secured. |
| 32 | +2. Set the **Value** to the base64-encoded private key we generated earlier. |
| 33 | +3. Click **Add**. |
| 34 | + |
| 35 | +To add hosts to the Pipeline known hosts go to **Repository settings -> Pipelines -> SSH Keys** |
| 36 | + |
| 37 | +1. Set **Host address** to your hypernode instance (e.g. _appname.hypernode.io_) |
| 38 | +2. Click **Fetch** to fetch the hostname fingerprint |
| 39 | +3. Click **Add Host** to add host to known hosts |
| 40 | +4. Repeat this for all hosts the pipeline will connect to (for example production, staging) |
| 41 | + |
| 42 | +## Build |
| 43 | + |
| 44 | +Create the file `bitbucket-pipelines.yml` with the contents below. |
| 45 | +This workflow will be used in other workflows. |
| 46 | + |
| 47 | +```yaml |
| 48 | +image: quay.io/hypernode/deploy:3-php8.2-node18 |
| 49 | + |
| 50 | +definition: |
| 51 | + steps: |
| 52 | + - step: &hypernode-build |
| 53 | + name: Build |
| 54 | + script: |
| 55 | + - hypernode-deploy build |
| 56 | + artifacts: |
| 57 | + - build/** |
| 58 | +``` |
| 59 | +
|
| 60 | +````{note} |
| 61 | +Don't forget to set the specifications of the image to what your project needs. The same goes for the deploy steps. |
| 62 | +For example, if your project needs PHP 7.4 and Node.js 16, set the image to: |
| 63 | +```yaml |
| 64 | +jobs: |
| 65 | + build: |
| 66 | + container: quay.io/hypernode/deploy:3-php7.4-node16 |
| 67 | + ... |
| 68 | +``` |
| 69 | +```` |
| 70 | +
|
| 71 | +## Deploy to production |
| 72 | +
|
| 73 | +Add the following to the `bitbucket-pipelines.yml` file. |
| 74 | +
|
| 75 | +```yaml |
| 76 | +pipelines: |
| 77 | + # Deploy to production |
| 78 | + master: |
| 79 | + - step: *hypernode-build |
| 80 | + - step: |
| 81 | + name: Deploy to production |
| 82 | + deployment: production |
| 83 | + script: |
| 84 | + - hypernode-deploy deploy production |
| 85 | +``` |
| 86 | +
|
| 87 | +## Deploy to acceptance |
| 88 | +
|
| 89 | +If you have an acceptance (or staging) stage in your deployment flow, here's an example on how to deploy that. |
| 90 | +
|
| 91 | +```yaml |
| 92 | +pipelines: |
| 93 | + # Deploy to acceptance |
| 94 | + acceptance: # acceptance/staging branch |
| 95 | + - step: *hypernode-build |
| 96 | + - step: |
| 97 | + name: Deploy to staging |
| 98 | + deployment: staging |
| 99 | + script: |
| 100 | + - hypernode-deploy deploy staging |
| 101 | +``` |
0 commit comments