Skip to content

Commit

Permalink
Merge pull request akvo#1536 from akvo/feature/1533-self-host
Browse files Browse the repository at this point in the history
[akvo#1533] Add production composite actions and and simplify frontend build
  • Loading branch information
ifirmawan authored Jul 16, 2024
2 parents b93b86a + 40629a2 commit 22329c5
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 1 deletion.
47 changes: 47 additions & 0 deletions .github/composite-actions/ssh-docker-compose/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Docker Compose Build and Restart

inputs:
server-ip:
description: 'Server IP address'
required: true
server-ssh-port:
description: 'Server SSH port'
required: true
server-ssh-secret-key:
description: 'The SSH secret key from server'
required: true
server-ssh-user:
description: 'SSH User'
required: true
docker-compose-file:
description: 'Docker compose file location'
required: true
docker-compose-file-frontend-build:
description: 'Docker compose for frontend build file location'
required: true
ci_commit:
description: 'Commit ID'
required: true

runs:
using: "composite"
steps:
- name: Write secret to file
run: echo "${{ inputs.server-ssh-secret-key }}" > priv.key && chmod 600 priv.key
shell: bash

- name: Git Pull
run: .github/composite-actions/ssh-docker-compose/git-pull.sh ${{ inputs.server-ip }} ${{ inputs.server-ssh-port }} ${{ inputs.server-ssh-user }}
shell: bash

- name: Rebuild Frontend
run: .github/composite-actions/ssh-docker-compose/frontend-build.sh ${{ inputs.server-ip }} ${{ inputs.server-ssh-port }} ${{ inputs.server-ssh-user }} ${{ inputs.docker-compose-file-frontend-build }} ${{ inputs.ci_commit }}
shell: bash

- name: Rebuild
run: .github/composite-actions/ssh-docker-compose/build.sh ${{ inputs.server-ip }} ${{ inputs.server-ssh-port }} ${{ inputs.server-ssh-user }} ${{ inputs.docker-compose-file }} ${{ inputs.ci_commit }}
shell: bash

- name: Up
run: .github/composite-actions/ssh-docker-compose/up.sh ${{ inputs.server-ip }} ${{ inputs.server-ssh-port }} ${{ inputs.server-ssh-user }} ${{ inputs.docker-compose-file }}
shell: bash
19 changes: 19 additions & 0 deletions .github/composite-actions/ssh-docker-compose/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu

# ${1} for Server IP
# ${2} for Server Port
# ${3} for Server User
# ${4} for Dockerfile location

server_ip="${1}"
server_port="${2}"
server_user="${3}"
docker_compose_file="${4}"
ci_commit="${5}"

ssh -i priv.key -o BatchMode=yes \
-p "${server_port}" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${server_user}"@"${server_ip}" "cd src/deploy && CI_COMMIT=${ci_commit} docker compose -f ${docker_compose_file} build --no-cache"
19 changes: 19 additions & 0 deletions .github/composite-actions/ssh-docker-compose/frontend-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash
set -eu

# ${1} for Server IP
# ${2} for Server Port
# ${3} for Server User
# ${4} for Dockerfile location

server_ip="${1}"
server_port="${2}"
server_user="${3}"
docker_compose_file="${4}"
ci_commit="${5}"

ssh -i priv.key -o BatchMode=yes \
-p "${server_port}" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${server_user}"@"${server_ip}" "cd src/deploy && CI_COMMIT=${ci_commit} docker compose -f ${docker_compose_file} up --build"
17 changes: 17 additions & 0 deletions .github/composite-actions/ssh-docker-compose/git-pull.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash
set -eu

# ${1} for Server IP
# ${2} for Server Port
# ${3} for Server User

server_ip="${1}"
server_port="${2}"
server_user="${3}"


ssh -i priv.key -o BatchMode=yes \
-p "${server_port}" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${server_user}"@"${server_ip}" "cd src/ && git pull"
18 changes: 18 additions & 0 deletions .github/composite-actions/ssh-docker-compose/up.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
set -eu

# ${1} for Server IP
# ${2} for Server Port
# ${3} for Server User
# ${4} for Dockerfile location

server_ip="${1}"
server_port="${2}"
server_user="${3}"
docker_compose_file="${4}"

ssh -i priv.key -o BatchMode=yes \
-p "${server_port}" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
"${server_user}"@"${server_ip}" "cd src/deploy && docker compose -f ${docker_compose_file} stop && docker compose -f ${docker_compose_file} up -d"
2 changes: 1 addition & 1 deletion deploy/docker-compose.frontend-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ services:
echo "PUBLIC_URL=/" > .env
sed 's/"warn"/"error"/g' < .eslintrc.json > .eslintrc.prod.json
sed "s/\"##CACHE_VERSION##\"/\"${CI_COMMIT}\"/g" < public/service-worker.template.js > public/service-worker.js
sh release.sh
sh release.prod.sh
volumes:
- ../frontend:/app:delegated
9 changes: 9 additions & 0 deletions frontend/release.prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash
#shellcheck disable=SC2039

set -euo pipefail

yarn install --no-progress --frozen-lock
yarn eslint --config .eslintrc.prod.json src --ext .js,.jsx
yarn prettier --check src/
yarn build

0 comments on commit 22329c5

Please sign in to comment.