Skip to content

Commit c62705f

Browse files
committed
Add production deployment
1 parent 80056c0 commit c62705f

File tree

3 files changed

+63
-15
lines changed

3 files changed

+63
-15
lines changed

.github/workflows/deploy.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: Deploy to acceptance server
22

33
on:
44
pull_request:
5+
push:
6+
branches:
7+
- 'master'
58

69
env:
710
COMPOSER_CACHE_DIR: /tmp/composer-cache
@@ -19,16 +22,18 @@ jobs:
1922
- uses: webfactory/ssh-agent@v0.5.4
2023
with:
2124
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
25+
- run: apt update && apt install -y python3 virtualenv
2226
- run: hypernode-deploy build -vvv
2327
- name: archive production artifacts
2428
uses: actions/upload-artifact@v3
2529
with:
2630
name: deployment-build
2731
path: build/build.tgz
2832

29-
deploy:
33+
deploy_acceptance:
3034
needs: build
3135
runs-on: ubuntu-latest
36+
if: github.ref != 'refs/heads/master'
3237
container: quay.io/hypernode/deploy:3-php8.1-node18
3338
steps:
3439
- uses: actions/checkout@v2
@@ -52,3 +57,22 @@ jobs:
5257
with:
5358
message: |
5459
Acceptance server is available at https://${{ env.BRANCHER_HOSTNAME }}
60+
61+
deploy_production:
62+
needs: build
63+
runs-on: ubuntu-latest
64+
if: github.ref == 'refs/heads/master'
65+
container: quay.io/hypernode/deploy:3-php8.1-node18
66+
steps:
67+
- uses: actions/checkout@v2
68+
- name: download build artifact
69+
uses: actions/download-artifact@v3
70+
with:
71+
name: deployment-build
72+
path: build/
73+
- uses: webfactory/ssh-agent@v0.5.4
74+
with:
75+
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
76+
- run: mkdir -p $HOME/.ssh
77+
- name: deploy to production
78+
run: hypernode-deploy deploy production -vvv

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
_build
33
*.pyc
44
.idea
5+
.venv
6+
pub
7+
.ssh
58
.vscode
69
*.css.map
710
deployment-report.json

deploy.php

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,63 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Hypernode\DeployConfiguration;
46

57
use function Deployer\after;
68
use function Deployer\run;
79
use function Deployer\task;
10+
use function Deployer\test;
811

912
$DOCKER_HOST = '172.17.0.2';
1013
$DOCKER_WEBROOT = sprintf('/data/web/apps/%s/current/pub', $DOCKER_HOST);
1114

1215
# Disable the symlinking of /data/web/public because we're gonna be deploying both staging and prod on 1 Hypernode.
1316
task('deploy:disable_public', function () {
14-
run("if ! test -d /data/web/public; then unlink /data/web/public; mkdir /data/web/public; fi");
17+
if (!test('[ -d /data/web/public ]')) {
18+
run('unlink /data/web/public');
19+
run('mkdir -p /data/web/public');
20+
}
1521
run("echo 'Not used, see /data/web/apps/ instead' > /data/web/public/index.html;");
1622
});
1723

1824
# Create the venv
1925
task('python:venv:create', static function () {
20-
run('mkdir -p {{release_path}}/.hypernode');
21-
run('virtualenv -p python3 {{release_path}}/.venv');
26+
run('mkdir -p .hypernode');
27+
run('virtualenv -p python3 .venv');
2228
});
2329

2430
# Install the requirements
2531
task('python:venv:requirements', static function () {
26-
run('source {{release_path}}/.venv/bin/activate && pip install -r {{release_path}}/requirements/base.txt');
32+
run('source .venv/bin/activate && pip install -r requirements/base.txt');
2733
});
2834

2935
# Build the documentation
3036
task('python:build_documentation', static function () {
31-
run('source {{release_path}}/.venv/bin/activate && cd {{release_path}} && {{release_path}}/bin/build_docs');
32-
run('ln -s {{release_path}}/docs/_build/html {{release_path}}/pub');
37+
run('source .venv/bin/activate && bin/build_docs');
38+
run('ln -s docs/_build/html pub');
3339
});
3440

3541
# HMV configuration for when this is running in a docker
3642
task('deploy:hmv_docker', static function () use (&$DOCKER_HOST, &$DOCKER_WEBROOT) {
37-
run(sprintf('if test -f /etc/hypernode/is_docker; then hypernode-manage-vhosts %s --disable-https --type generic-php --yes --webroot %s --default-server; fi', $DOCKER_HOST, $DOCKER_WEBROOT));
43+
if (test('[ -f /etc/hypernode/is_docker ]')) {
44+
run(sprintf(
45+
'hypernode-manage-vhosts %s --disable-https --type generic-php --yes --webroot %s --default-server',
46+
$DOCKER_HOST,
47+
$DOCKER_WEBROOT,
48+
));
49+
}
3850
});
3951

4052
task("deploy:docs_vhost", static function () {
41-
run("hypernode-manage-vhosts --https --force-https {{hostname}} --webroot {{current_path}}/{{public_folder}}");
53+
run("hypernode-manage-vhosts --https --force-https {{hostname}} --no --webroot {{current_path}}/{{public_folder}}");
4254
});
4355

4456
$configuration = new Configuration();
57+
$configuration->addBuildTask('python:venv:create');
58+
$configuration->addBuildTask('python:venv:requirements');
59+
$configuration->addBuildTask('python:build_documentation');
4560
$configuration->addDeployTask('deploy:disable_public');
46-
$configuration->addDeployTask('python:venv:create');
47-
$configuration->addDeployTask('python:venv:requirements');
48-
$configuration->addDeployTask('python:build_documentation');
4961
$configuration->addDeployTask('deploy:hmv_docker');
5062
$configuration->addDeployTask('deploy:docs_vhost');
5163

@@ -54,15 +66,24 @@
5466
'./.git',
5567
'./.github',
5668
'./deploy.php',
57-
'./.gitlab-ci.yml',
58-
'./Jenkinsfile',
69+
'./.pre-commit-config.yaml',
70+
'./documentation_urls.txt',
71+
'./tox.ini',
5972
'.DS_Store',
6073
'.idea',
6174
'.gitignore',
6275
'.editorconfig',
63-
'etc/'
76+
'etc/',
77+
'.venv/',
78+
'bin/',
79+
'hypernode/',
80+
'requirements/',
81+
'tests/'
6482
]);
6583

84+
$productionStage = $configuration->addStage('production', 'docs.hypernode.io');
85+
$productionStage->addServer('docs.hypernode.io');
86+
6687
# We can also deploy to a Hypernode Docker instance. To do that you go to
6788
# https://github.com/byteinternet/hypernode-docker, make sure you
6889
# have an instance running by for example doing:

0 commit comments

Comments
 (0)