Skip to content

Commit 6e672d1

Browse files
authored
Merge pull request #295 from poespas/feature/add_docs_for_bitbucket_pipelines
Add hypernode-deploy documentation for Bitbucket pipelines
2 parents 87f0ab9 + 5fa8645 commit 6e672d1

File tree

1 file changed

+112
-1
lines changed

1 file changed

+112
-1
lines changed
Lines changed: 112 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,114 @@
11
# Bitbucket Pipelines
22

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+
#### Use Bitbucket repository SSH Keys
18+
19+
Bitbucket allows you to create an SSH key from the Repository Settings, you do this by going to **Repository Settings -> Pipelines -> SSH Keys**
20+
21+
1. Under **SSH key** press the **Generate keys** button.
22+
1. Copy the Public key as showed in the textbox to the `~/.ssh/authorized_keys` file on your host.
23+
24+
#### Generating own pair of SSH Keys
25+
26+
You cangenerate an SSH keypair on the server, copy the public key to the `~/.ssh/authorized_keys` file
27+
and encode the private key with base64. We'll use this base64-encoded private key later on.
28+
29+
```console
30+
app@abc-example-magweb-cmbl:~$ ssh-keygen -t ed25519 -C bb-pipelines-deploy -f bb-pipelines-deploy -q -P ""
31+
app@abc-example-magweb-cmbl:~$ cat bb-pipelines-deploy.pub >> ~/.ssh/authorized_keys
32+
app@abc-example-magweb-cmbl:~$ cat bb-pipelines-deploy | base64 -w0 # encode the private key with base64
33+
LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtV...
34+
```
35+
36+
Now go to your Bitbucket repository and enable Bitbucket pipelines being going to **Repository settings -> Pipelines -> Settings** and turn on **Enable Pipelines**.
37+
38+
Now go to **Repository settings -> Pipelines -> Repository variables**.
39+
40+
```{note}
41+
If you used Bitbucket Pipeline SSH Keys as described above, you do not need to add an `SSH_PRIVATE_KEY` environment variable.
42+
```
43+
44+
1. Create a new variable with name `SSH_PRIVATE_KEY`, mark this variable as Secured.
45+
1. Set the **Value** to the base64-encoded private key we generated earlier.
46+
1. Click **Add**.
47+
48+
To add hosts to the Pipeline known hosts go to **Repository settings -> Pipelines -> SSH Keys**
49+
50+
1. Set **Host address** to your hypernode instance (e.g. _appname.hypernode.io_)
51+
1. Click **Fetch** to fetch the hostname fingerprint
52+
1. Click **Add Host** to add host to known hosts
53+
1. Repeat this for all hosts the pipeline will connect to (for example production, staging)
54+
55+
## Build
56+
57+
Create the file `bitbucket-pipelines.yml` with the contents below.
58+
This workflow will be used in other workflows.
59+
60+
```yaml
61+
image: quay.io/hypernode/deploy:3-php8.2-node18
62+
63+
definition:
64+
steps:
65+
- step: &hypernode-build
66+
name: Build
67+
script:
68+
- hypernode-deploy build
69+
artifacts:
70+
- build/**
71+
```
72+
73+
````{note}
74+
Don't forget to set the specifications of the image to what your project needs. The same goes for the deploy steps.
75+
For example, if your project needs PHP 7.4 and Node.js 16, set the image to:
76+
```yaml
77+
jobs:
78+
build:
79+
container: quay.io/hypernode/deploy:3-php7.4-node16
80+
...
81+
```
82+
````
83+
84+
## Deploy to production
85+
86+
Add the following to the `bitbucket-pipelines.yml` file.
87+
88+
```yaml
89+
pipelines:
90+
# Deploy to production
91+
master:
92+
- step: *hypernode-build
93+
- step:
94+
name: Deploy to production
95+
deployment: production
96+
script:
97+
- hypernode-deploy deploy production
98+
```
99+
100+
## Deploy to acceptance
101+
102+
If you have an acceptance (or staging) stage in your deployment flow, here's an example on how to deploy that.
103+
104+
```yaml
105+
pipelines:
106+
# Deploy to acceptance
107+
acceptance: # acceptance/staging branch
108+
- step: *hypernode-build
109+
- step:
110+
name: Deploy to staging
111+
deployment: staging
112+
script:
113+
- hypernode-deploy deploy staging
114+
```

0 commit comments

Comments
 (0)