From 2da9c02d5869aae9e17a42dd41a38e93db544f22 Mon Sep 17 00:00:00 2001 From: Lev Date: Sun, 31 Oct 2021 08:32:58 +0300 Subject: [PATCH] ci: Build fixes - Simplify builds by separating dev/stable workflows - Fix Helm deploy key - Remove deploy_key.env (already using deploy key in secrets) - Fix paths matching on push and pull_request triggers - Fix possible issues with tag difference between ERPNext and Frappe (add tag resolving step before pushing) - Don't login, push Docker images and release Helm chart on forks - Don't test on version 12 (there's no test for this version) - Remove frappe-installer (from chore: use github actions #525) - Fix badges in readme --- .github/scripts/get-latest-tag.sh | 5 +- .github/scripts/install-deps-and-test.sh | 11 + .github/workflows/build_develop.yml | 88 ++++++++ .github/workflows/build_stable.yml | 111 ++++++++++ .github/workflows/docker.yml | 193 ----------------- README.md | 5 +- deploy_key.enc | Bin 3360 -> 0 bytes frappe-installer | 255 ----------------------- 8 files changed, 216 insertions(+), 452 deletions(-) create mode 100755 .github/scripts/install-deps-and-test.sh create mode 100644 .github/workflows/build_develop.yml create mode 100644 .github/workflows/build_stable.yml delete mode 100644 .github/workflows/docker.yml delete mode 100644 deploy_key.enc delete mode 100755 frappe-installer diff --git a/.github/scripts/get-latest-tag.sh b/.github/scripts/get-latest-tag.sh index 1ce4bc38..1af75311 100755 --- a/.github/scripts/get-latest-tag.sh +++ b/.github/scripts/get-latest-tag.sh @@ -2,4 +2,7 @@ TAGS=$(git ls-remote --refs --tags --sort='v:refname' https://github.com/$REPO "v$VERSION.*") TAG=$(echo $TAGS | tail -n1 | sed 's/.*\///') -echo $TAG + +echo "GIT_TAG=$TAG" >> $GITHUB_ENV +echo "GIT_BRANCH=version-$VERSION" >> $GITHUB_ENV +echo "VERSION=$VERSION" >> $GITHUB_ENV \ No newline at end of file diff --git a/.github/scripts/install-deps-and-test.sh b/.github/scripts/install-deps-and-test.sh new file mode 100755 index 00000000..39d5e0f1 --- /dev/null +++ b/.github/scripts/install-deps-and-test.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +sudo apt-get install -y w3m + +./tests/check-format.sh +./tests/docker-test.sh + +# This is done to not to rebuild images in the next step +git clean -fdx \ No newline at end of file diff --git a/.github/workflows/build_develop.yml b/.github/workflows/build_develop.yml new file mode 100644 index 00000000..a4ee5a29 --- /dev/null +++ b/.github/workflows/build_develop.yml @@ -0,0 +1,88 @@ +name: Build Develop + +on: + pull_request: + branches: + - main + paths: + - .github/** + - build/** + - installation/** + - tests/** + - .dockerignore + - docker-bake.hcl + - docker-compose.yml + - env* + + # Nightly builds at 12:00 am + schedule: + - cron: 0 0 * * * + + workflow_dispatch: + +jobs: + build_bench: + name: Bench image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + + - uses: docker/login-action@v1 + if: github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-bench + push: ${{ github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' }} + + build_main: + name: Frappe and ERPNext images + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + + - uses: docker/login-action@v1 + if: github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build Frappe images + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-develop + load: true + + - name: Build ERPNext images + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: erpnext-develop + load: true + + - name: Test + run: ./.github/scripts/install-deps-and-test.sh + + - name: Push Frappe images + if: github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-develop + push: true + + - name: Push ERPNext images + if: github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: erpnext-develop + push: true diff --git a/.github/workflows/build_stable.yml b/.github/workflows/build_stable.yml new file mode 100644 index 00000000..8c615286 --- /dev/null +++ b/.github/workflows/build_stable.yml @@ -0,0 +1,111 @@ +name: Build Stable + +on: + push: + branches: + - main + paths: + - .github/** + - build/** + - installation/** + - tests/** + - .dockerignore + - docker-bake.hcl + - docker-compose.yml + - env* + + # Triggered from frappe/frappe and frappe/erpnext on releases + repository_dispatch: + + workflow_dispatch: + +jobs: + build: + name: Frappe and ERPNext images + runs-on: ubuntu-latest + strategy: + matrix: + version: [12, 13] + + steps: + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + - uses: docker/login-action@v1 + if: github.repository == 'frappe/frappe_docker' + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Setup Frappe variables + run: ./.github/scripts/get-latest-tag.sh + env: + REPO: frappe/frappe + VERSION: ${{ matrix.version }} + + - name: Build Frappe images + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-stable + load: true + + - name: Setup ERPNext variables + run: ./.github/scripts/get-latest-tag.sh + env: + REPO: frappe/erpnext + VERSION: ${{ matrix.version }} + + - name: Build ERPNext images + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: erpnext-stable + load: true + + - name: Test + if: ${{ matrix.version != 12 }} + run: ./.github/scripts/install-deps-and-test.sh + + - name: Setup Frappe variables + if: github.repository == 'frappe/frappe_docker' + run: ./.github/scripts/get-latest-tag.sh + env: + REPO: frappe/frappe + VERSION: ${{ matrix.version }} + + - name: Push Frappe images + if: github.repository == 'frappe/frappe_docker' + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-stable + push: true + + - name: Setup ERPNext variables + if: github.repository == 'frappe/frappe_docker' + run: ./.github/scripts/get-latest-tag.sh + env: + REPO: frappe/erpnext + VERSION: ${{ matrix.version }} + + - name: Push ERPNext images + if: github.repository == 'frappe/frappe_docker' + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: erpnext-stable + push: true + + - name: Setup Helm deploy key + if: github.repository == 'frappe/frappe_docker' + uses: webfactory/ssh-agent@v0.5.3 + with: + ssh-private-key: ${{ secrets.HELM_DEPLOY_KEY }} + + - name: Release Helm Chart + if: github.repository == 'frappe/frappe_docker' + run: | + pip install --upgrade pip + git clone git@github.com:frappe/helm.git && cd helm + pip install -r release_wizard/requirements.txt + ./release_wizard/wizard 13 patch --remote origin --ci diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index a1166045..00000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,193 +0,0 @@ -name: Build - -on: - push: - branches: - - main - paths: - - .github/workflows/docker.yml - - build/** - - installation/** - - tests/** - - .dockerignore - - docker-bake.hcl - - docker-compose.yml - - env* - - pull_request: - branches: - - main - paths: - - .github/workflows/docker.yml - - build/** - - installation/** - - tests/** - - .dockerignore - - docker-bake.hcl - - docker-compose.yml - - env* - - # Nightly builds at 12:00 am - schedule: - - cron: 0 0 * * * - - repository_dispatch: # Triggered from frappe/frappe and frappe/erpnext on releases - - workflow_dispatch: # Manually triggered - inputs: - version: - description: Frappe and ERPNext version. Set to "12", "13" for latest stable versions or "develop" for nightly builds. - required: true - -jobs: - resolve-matrix: - name: Resolve matrix configuration - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.get-matrix.outputs.matrix }} - build-target: ${{ steps.get-build-target.outputs.build-target }} - - steps: - - uses: actions/checkout@v2 - - - name: Get matrix - id: get-matrix - run: | - if [ $GITHUB_EVENT_NAME == "repository_dispatch" ] || [ $GITHUB_EVENT_NAME == "push" ]; then - MATRIX='[{"version": "12"}, {"version": "13"}]' - elif [ $GITHUB_EVENT_NAME == "schedule" ] || [ $GITHUB_EVENT_NAME == "pull_request" ]; then - MATRIX='[{"version": "develop"}]' - elif [ $GITHUB_EVENT_NAME == "workflow_dispatch" ]; then - MATRIX='[{"version": "${{ github.event.inputs.version }}"}]' - fi - - echo ::set-output name=matrix::{\"include\":$MATRIX} - echo $MATRIX - - - name: Get build target - id: get-build-target - run: | - IS_DEVELOP=$(echo $MATRIX | jq 'any(.include[].version == "develop"; .)') - if [ $IS_DEVELOP == "true" ]; then - BUILD_TARGET_SUFFIX="develop" - else - BUILD_TARGET_SUFFIX="stable" - fi - echo $BUILD_TARGET_SUFFIX - echo ::set-output name=build-target::$BUILD_TARGET_SUFFIX - env: - MATRIX: ${{ steps.get-matrix.outputs.matrix }} - - build_bench: - name: Bench image - needs: resolve-matrix - runs-on: ubuntu-latest - if: needs.resolve-matrix.outputs.build-target == 'develop' - - steps: - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - uses: docker/login-action@v1 - if: github.event_name != 'pull_request' - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: frappe-bench - push: ${{ github.event_name != 'pull_request' }} - - build_main: - name: Frappe and ERPNext images - runs-on: ubuntu-latest - strategy: - matrix: ${{ fromJson(needs.resolve-matrix.outputs.matrix) }} - needs: resolve-matrix - - steps: - - uses: actions/checkout@v2 - - uses: docker/setup-buildx-action@v1 - - uses: docker/login-action@v1 - if: github.event_name != 'pull_request' - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Get latest Frappe tag - if: needs.resolve-matrix.outputs.build-target == 'stable' - run: | - GIT_TAG=$(./.github/scripts/get-latest-tag.sh) - echo $GIT_TAG - echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV - echo "GIT_BRANCH=version-$VERSION" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - env: - REPO: frappe/frappe - VERSION: ${{ matrix.version }} - - - name: Build Frappe images - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: ${{ format('{0}-{1}', 'frappe', needs.resolve-matrix.outputs.build-target )}} - load: true - - - name: Get latest ERPNext tag - if: needs.resolve-matrix.outputs.build-target == 'stable' - run: | - GIT_TAG=$(./.github/scripts/get-latest-tag.sh) - echo $GIT_TAG - echo "GIT_TAG=$GIT_TAG" >> $GITHUB_ENV - echo "GIT_BRANCH=version-$VERSION" >> $GITHUB_ENV - echo "VERSION=$VERSION" >> $GITHUB_ENV - env: - REPO: frappe/erpnext - VERSION: ${{ matrix.version }} - - - name: Build ERPNext images - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: ${{ format('{0}-{1}', 'erpnext', needs.resolve-matrix.outputs.build-target )}} - load: true - - - name: Install test dependencies - run: sudo apt-get install -y w3m - - - name: Test - if: github.event_name == 'pull_request' - run: | - ./tests/check-format.sh - ./tests/docker-test.sh - # This is done to not to rebuild images in the next step - git reset --hard @{u} - - - name: Push Frappe images - if: github.event_name != 'pull_request' - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: ${{ format('{0}-{1}', 'frappe', needs.resolve-matrix.outputs.build-target )}} - push: true - - - name: Push ERPNext images - if: github.event_name != 'pull_request' - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: ${{ format('{0}-{1}', 'erpnext', needs.resolve-matrix.outputs.build-target )}} - push: true - - - name: Release Helm Chart - if: needs.resolve-matrix.outputs.build-target == 'stable' - uses: webfactory/ssh-agent@v0.5.3 - with: - ssh-private-key: ${{ secrets.HELM_DEPLOY_KEY }} - run: | - pip install --upgrade pip - git clone git@github.com:frappe/helm.git && cd helm - pip install -r release_wizard/requirements.txt - ./release_wizard/wizard 13 patch --remote origin --ci diff --git a/README.md b/README.md index f49da5c5..a346ca6a 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ -| Stable | [![stable](https://github.com/frappe/frappe_docker/actions/workflows/docker.yml/badge.svg?event=repository_dispatch)](https://github.com/frappe/frappe_docker/actions/workflows/docker.yml) | -|---------|-----------------------------------------------------------------------------------------------------------------------------| -| Nightly | [![nightly](https://github.com/frappe/frappe_docker/actions/workflows/docker.yml/badge.svg?event=schedule)](https://github.com/frappe/frappe_docker/actions/workflows/docker.yml) | +[![Build Stable](https://github.com/frappe/frappe_docker/actions/workflows/build_stable.yml/badge.svg)](https://github.com/frappe/frappe_docker/actions/workflows/build_stable.yml) +[![Build Develop](https://github.com/frappe/frappe_docker/actions/workflows/build_develop.yml/badge.svg)](https://github.com/frappe/frappe_docker/actions/workflows/build_develop.yml) ## Getting Started diff --git a/deploy_key.enc b/deploy_key.enc deleted file mode 100644 index 01360cdfc772214041093f4221064f78815c8c61..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3360 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 diff --git a/frappe-installer b/frappe-installer deleted file mode 100755 index e379f84b..00000000 --- a/frappe-installer +++ /dev/null @@ -1,255 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -IFS=$'\n\t' - -[[ -z "${DEBUG}" && "${DEBUG}" == 1 ]] && set -o xtrace - -__dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -cd "$__dir" - -env_url="https://raw.githubusercontent.com/frappe/frappe_docker/master/installation/env-example" -docker_nginx_url="https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion" -frappe_docker_url="https://github.com/frappe/frappe_docker" -env_file="$__dir/.env" - -function check_root() { - if [[ $EUID != 0 ]]; then - echo "This script must be run as root. Login as root or use sudo." >&2 - exit 1 - fi -} - -function check_git() { - if [[ ! -x "$(command -v git)" ]]; then - echo "Git is not installed. Please install git before continuing." >&2 - exit 1 - fi -} - -function check_docker() { - if [[ ! -x "$(command -v docker)" ]]; then - read -rp "No docker installation found. Press Enter to install docker or ctrl+c to exit." >&2 - curl -fsSL https://get.docker.com | sh - fi - if [[ ! -x "$(command -v docker)" ]]; then - echo "Docker installation failed. Exiting." >&2 - exit 1 - fi -} - -function check_env() { - if [[ ! -f "$env_file" ]]; then - cat <&2 - No environment file found. This file is required for setting up Frappe/ERPNext Docker. - Would you like to fetch the default environment file? - (NOTE: You will be prompted to set it up later) -CHOOSE - read -rp "Press Enter to fetch the configuration file, or create a .env file and re-run the script." - curl -fsSL "$env_url" -o "$env_file" - fi -} - -function clone_repository() { - echo "Cloning Repository: $1" - git clone "$2" -} - -function get_config() { - if [[ -n "$2" ]]; then - config_file="$2" - else - config_file="$env_file" - fi - line=$(grep -E "^$=" "$config_file") - line_result=$(echo "$line" | awk -F"=" '{print $2}') -} - -function get_install_version() { - cat <&2 - Choose a version you would like to setup [current: $1]: - 1. develop (edge) - 2. version-12 - 3. version-11 - Please enter your choice [1-3]: -CHOOSE - select choice in "1" "2" "3"; do - case ${choice} in - 1) version="edge" ;; - 2) version="version-12" ;; - 3) version="version-11" ;; - esac - done -} - -function prompt_config() { - # inspired by discourse_docker - get_config "VERSION" - local install_version=$line_result - get_config "MYSQL_ROOT_PASSWORD" - local mysql_password=$line_result - get_config "SITES" - local sites=$line_result - get_config "LETSENCRYPT_EMAIL" - local letsencrypt_email=$line_result - - echo "Would you like to setup networking for docker? [y/n]" - echo "This is required if you wish to access the instance from other machines." - select choice in "y" "n"; do - case $choice in - y) setup_networking=1 ;; - n) - setup_networking=0 - setup_letsencrypt=0 - ;; - esac - done - if [[ -n "$letsencrypt_email" && "$setup_networking" -ne "0" ]]; then - echo "Would you like to setup LetsEncrypt? [y/n]" - select choice in "y" "n"; do - case $choice in - y) - setup_letsencrypt=1 - echo "Please ensure that all the required domains point to this IP address." - read -rp "Enter an Email Address to setup LetsEncrypt with: " letsencrypt_email - ;; - n) - setup_letsencrypt=0 - echo "Skipping LetsEncrypt Setup." - ;; - esac - done - fi - - local new_value="" - local config_state="n" - - echo - - get_install_version "$install_version" - install_version="$version" - - while [[ "$config_state" == "n" ]]; do - if [[ -n "$mysql_password" ]]; then - read -srp "Enter MySQL Password [$mysql_password]: " new_value - if [[ -n "$new_value" ]]; then - mysql_password="$new_value" - fi - fi - - if [[ -n "$sites" ]]; then - read -rp "Enter sitename to setup [$sites]: " new_value - if [[ -n "$new_value" ]]; then - sites="$new_value" - fi - fi - - if [[ "$setup_letsencrypt" != "0" ]]; then - read -rp "Enter email address for LetsEncrypt [$letsencrypt_email]: " new_value - if [[ -n "$new_value" ]]; then - letsencrypt_email=$new_value - fi - fi - - echo "Current Configuration:" - echo "Version: $([[ "$install_version" == "edge" ]] && echo "develop" || echo "$install_version")" - echo "MySQL Root Password: $mysql_password" - echo "Sites: $sites" - - if [[ "$setup_letsencrypt" != "0" ]]; then - echo "LetsEncrypt Email Address: $letsencrypt_email" - fi - - echo - echo "Does this configuration look okay?" - read -rp "Press Enter to continue, 'n' to try again, or ctrl+c to exit: " config_state - done - - echo "Saving the current configuration file to $env_file" - - cat <"$env_file" -VERSION=$install_version -MYSQL_ROOT_PASSWORD=$mysql_password -SITES=$sites -$([ "$setup_letsencrypt" -ne "0" ] && echo "LETSENCRYPT_EMAIL=$letsencrypt_email") -EOF - setup_configuration=$(<"$env_file") -} - -setup_user() { - echo "The rest of the setup requires a user account." - echo "You may use an existing account, or set up a new one right away." - read -rp "Enter username: " username - if grep -E "^$username" /etc/passwd >/dev/null; then - echo "User $username already exists." - else - read -rsp "Enter password: " password - password="$(perl -e 'print crypt($ARGV[0], "password")' "$password")" - if useradd -m -p "$password" "$username" -s "$(command -v bash)"; then - echo "User $username has been added to the system." - else - echo "Failed to add user to the system." - echo "Please add a user manually and re-run the script." - exit 1 - fi - fi - - if ! getent group docker >/dev/null 2>&1; then - echo "Creating group: docker" - groupadd docker - fi - echo "Adding user $username to group: docker" - usermod -aG docker "$username" - newgrp docker -} - -install() { - if [[ "$setup_letsencrypt" != "0" && "$setup_networking" != "0" ]]; then - echo "Setting up NGINX Proxy for LetsEncrypt" - clone_repository "Docker Compose LetsEncrypt NGINX Proxy Companion" "$docker_nginx_url" - cd "$(basename "$docker_nginx_url")" - if [[ -f .env.sample ]]; then - cp .env.sample env - fi - ./start.sh >/dev/null 2>&1 - cd "$(eval echo ~"$username")" - fi - - echo "Setting up Frappe/ERPNext" - clone_repository "Frappe/ERPNext Docker" "$frappe_docker_url" - cd "$(basename "$frappe_docker_url")" - echo "$setup_configuration" >.env - echo "Enter a name for the project." - read -rp "This project name will be used to setup the docker instance: [erpnext_docker]" project_name - if [[ -z "$project_name" ]]; then - echo "Setting the project name to erpnext_docker" - project_name="erpnext_docker" - fi - - docker-compose \ - --project-name "$project_name" \ - --project-directory . up -d \ - -f installation/docker-compose-frappe.yml \ - -f installation/docker-compose-erpnext.yml \ - -f installation/docker-compose-common.yml \ - "$( ((setup_networking == 1)) && printf %s '-f installation/docker-compose-networks.yml')" - - get_config "SITES" "$(pwd)/.env" - local sites=$line_result - - docker exec \ - -e "SITE_NAME=$sites" \ - -e "INSTALL_ERPNEXT=1" \ - -it "$project_name"_erpnext-python_1 docker-entrypoint.sh new - - echo "Installation Complete!" -} - -check_root -check_git -check_docker -check_env - -prompt_config -setup_user -install