Skip to content

Commit

Permalink
[MIG] pkg: make 'demo, test, dev1, dev2, dev3' branches deploy code
Browse files Browse the repository at this point in the history
  • Loading branch information
StΓ©phan SainlΓ©ger committed Jul 19, 2024
1 parent 0dcb23d commit 65d68b7
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 0 deletions.
129 changes: 129 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Continuous integration

## Global picture

Hosts are available through sftp (sftp is using ssh). The
authentication is the SSH one through a private key on the github side
(managed in github secrets) and accessible through
`secrets.sftp_private_key` in the yaml workflow definition.

All content of the workdir is sent to the hosts (ideally mirrored and
only difference should be sent), but this is not yet the case for
`lftp` limitation over using `sftp` and setting dates
correctly. `rclone` should be able to handle this better but is not
yet used. A simple git push could be studied also.

To trigger the restart of odoo on the host, we set up a inotify
watcher through `incron`.

## Host setup

### odoo

To add `odoo` services to a compose read host, add this section to
your `compose.yml`:

```yaml
odoo:
charm: odoo-tecnativa
docker-compose:
command:
- "--dev=xml,qweb,werkzeug"
- "--log-level=debug"
- "--limit-time-cpu=500"
- "--limit-time-real=500"
- "--limit-memory-soft=25273917440"
- "--limit-memory-hard=25273917440"
- "--addons-path=/opt/odoo/auto/lokavaluto,/opt/odoo/auto/addons"
volumes:
- /srv/datastore/data/odoo/opt/odoo/auto/lokavaluto:/opt/odoo/auto/lokavaluto:rw
image: docker.0k.io/mirror/odoo:rc_12.0-MYC-INIT-3.7
options:
workers: 4
modules:
- lcc_lokavaluto_app_connection
- lcc_comchain_base
- lcc_cyclos_base
relations:
web-proxy:
frontend:
domain: odoo.mydomain.org
```
Notice:
- the `--addons` path correlates with the `volumes` section.
- the `modules` section list the current modules

### sftp

To add `sftp` services to a compose ready host, add this section to
your `compose.yml`:

```yaml
sftp:
docker-compose:
ports:
- "10322:22"
volumes:
- /srv/datastore/data/odoo/opt/odoo/auto/lokavaluto:/home/monujo/lokavaluto-addons:rw
options:
users:
monujo:
groups:
- monujo-rw:3000
password: yLzTieeTwJmMlFZG
keys:
- "ssh-rsa AAAAB3N...PUBLICKEYGOESHERE... [email protected]"
```

The volumes section allows to `publish` and give access to the place
where odoo reads the module's code.

The public key is the public key part corresponding to the private key
that needs to be sent by the client (in github secrets).

Note that group `monujo-rw` is important. You should give the right of
all files that are to be modified the group `3000` from the host:

```
chown 1000:3000 /srv/datastore/data/odoo/opt/odoo/auto/lokavaluto -R
```

### incron

Incron is the tool used for the github deployement to signal the end
of the upload of the new files. It should trigger a restart of the
odoo docker.

Directory that allows triggering the event must be created and
permissions should be set so sftp user can write in it:

```bash
mkdir -p /srv/datastore/data/sftp/home/monujo/lokavaluto-addons.updated
cd /srv/datastore/data/sftp/home/monujo/lokavaluto-addons.updated
chown 1000:3000 -R .
```

To install `incron`:

```bash
apt-get install incron
echo "root" > /etc/incron.allow
```

To edit:

```bash
EDITOR=vim incrontab -e
```

Line to create in current installation

```
/srv/datastore/data/sftp/home/monujo/lokavaluto-addons.updated IN_CREATE,IN_MODIFY docker restart myc_odoo_1
```
It is expected that the client will delete and add a file in folder:
`lokavaluto-addons.updated` to trigger the reload.
54 changes: 54 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: "πŸš€ deploy CI"
on:
push:
branches:
- demo
- test
- dev1
- dev2
- dev3
paths-ignore:
- 'README*'

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
steps:
- name: 🚚 Get code
uses: actions/checkout@v2

## XXXvlab: contrary two what was expected from ltfp in mirror
## mode, this setup is highly inefficient: because through sftp,
## lftp is not able to set correctly dates so it just delete and
## rewrite everything on the other end. We need to change that
## with ``rclone`` solution I guess if we don't want to change
## ``sftp`` protocol.
- name: "πŸ“‚ SFTP Sync files"
uses: swillner/[email protected]
with:
server: ${{ github.ref_name }}.lokavaluto.fr
port: 10322
user: monujo
user_private_key: ${{ secrets.sftp_private_key }}
host_public_key:
local: ./
remote: /lokavaluto-addons
mirror_options: "--exclude-glob=.git*/ --verbose"
## This part is to ensure that we can trigger actions after
## the sync occured on the destination host.
- name: πŸ”¨ Prepare last-updated
run: |
mkdir last-updated
date > last-updated/done
- name: "πŸ“‚ SFTP Send last-updated"
uses: swillner/[email protected]
with:
server: ${{ github.ref_name }}.lokavaluto.fr
port: 10322
user: monujo
user_private_key: ${{ secrets.sftp_private_key }}
host_public_key:
local: ./last-updated
remote: /lokavaluto-addons.updated
mirror_options: "--verbose"

0 comments on commit 65d68b7

Please sign in to comment.