diff --git a/.github/workflows/build_develop.yml b/.github/workflows/build_develop.yml index 90f9876c..cfabd7a6 100644 --- a/.github/workflows/build_develop.yml +++ b/.github/workflows/build_develop.yml @@ -55,15 +55,22 @@ jobs: targets: bench-build push: true - build_frappe: - name: Frappe + build_main: + name: Frappe & ERPNext runs-on: ubuntu-latest + services: + registry: + image: registry:2 + ports: + - 5000:5000 steps: - name: Checkout uses: actions/checkout@v2 - name: Setup Buildx uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host - name: Login uses: docker/login-action@v1 @@ -72,56 +79,37 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Build + - name: Build Frappe uses: docker/bake-action@v1.6.0 with: files: docker-bake.hcl targets: frappe-develop-test load: true - - name: Test - run: ./tests/test-frappe.sh - - - name: Push - if: env.IS_AUTHORIZED_RUN == 'true' + - name: Push Frappe to local registry uses: docker/bake-action@v1.6.0 with: files: docker-bake.hcl - targets: frappe-develop + targets: frappe-develop-test-local push: true - build_erpnext: - name: ERPNext - runs-on: ubuntu-latest - needs: build_frappe - steps: - - name: Checkout - uses: actions/checkout@v2 + - name: Test Frappe + run: ./tests/test-frappe.sh - - name: Setup Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login - uses: docker/login-action@v1 - if: env.IS_AUTHORIZED_RUN == 'true' - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build + - name: Build ERPNext uses: docker/bake-action@v1.6.0 with: files: docker-bake.hcl targets: erpnext-develop-test load: true - - name: Test - run: FRAPPE_VERSION=develop ./tests/test-erpnext.sh + - name: Test ERPNext + run: ./tests/test-erpnext.sh - name: Push if: env.IS_AUTHORIZED_RUN == 'true' uses: docker/bake-action@v1.6.0 with: files: docker-bake.hcl - targets: erpnext-develop + targets: frappe-develop,erpnext-develop push: true diff --git a/.github/workflows/build_stable.yml b/.github/workflows/build_stable.yml index 6d5ad7f3..1e4eff02 100644 --- a/.github/workflows/build_stable.yml +++ b/.github/workflows/build_stable.yml @@ -35,19 +35,25 @@ env: IS_AUTHORIZED_RUN: ${{ github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' }} jobs: - build_frappe: - name: Frappe + build: + name: Frappe & ERPNext runs-on: ubuntu-latest strategy: matrix: version: [12, 13] - + services: + registry: + image: registry:2 + ports: + - 5000:5000 steps: - name: Checkout uses: actions/checkout@v2 - name: Setup Buildx uses: docker/setup-buildx-action@v1 + with: + driver-opts: network=host - name: Login uses: docker/login-action@v1 @@ -61,14 +67,36 @@ jobs: env: VERSION: ${{ matrix.version }} - - name: Build + - name: Build Frappe uses: docker/bake-action@v1.6.0 with: files: docker-bake.hcl targets: frappe-stable-test load: true - - name: Push + - name: Push Frappe to local registry + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: frappe-stable-test-local + push: true + + - name: Test Frappe + if: github.event_name == 'pull_request' + run: ./tests/test-frappe.sh + + - name: Build ERPNext + uses: docker/bake-action@v1.6.0 + with: + files: docker-bake.hcl + targets: erpnext-stable-test + load: true + + - name: Test ERPNext + if: github.event_name == 'pull_request' + run: ./tests/test-erpnext.sh + + - name: Push Frappe if: env.IS_AUTHORIZED_RUN == 'true' uses: docker/bake-action@v1.6.0 with: @@ -78,41 +106,7 @@ jobs: env: GIT_TAG: ${{ env.FRAPPE_VERSION }} - build_erpnext: - name: ERPNext - runs-on: ubuntu-latest - needs: build_frappe - strategy: - matrix: - version: [12, 13] - - steps: - - name: Checkout - uses: actions/checkout@v2 - - - name: Setup Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login - uses: docker/login-action@v1 - if: env.IS_AUTHORIZED_RUN == 'true' - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Get latest versions - run: ./.github/scripts/get-latest-tags.sh - env: - VERSION: ${{ matrix.version }} - - - name: Build - uses: docker/bake-action@v1.6.0 - with: - files: docker-bake.hcl - targets: erpnext-stable-test - load: true - - - name: Push + - name: Push ERPNext if: env.IS_AUTHORIZED_RUN == 'true' uses: docker/bake-action@v1.6.0 with: @@ -126,7 +120,7 @@ jobs: name: Release Helm runs-on: ubuntu-latest if: github.repository == 'frappe/frappe_docker' && github.event_name != 'pull_request' - needs: [build_frappe, build_erpnext] + needs: build steps: - name: Setup deploy key diff --git a/docker-bake.hcl b/docker-bake.hcl index 43a9a460..39379284 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -1,4 +1,8 @@ -# Images +# Docker Buildx Bake build definition file +# Reference: https://github.com/docker/buildx/blob/master/docs/reference/buildx_bake.md + + +# Bench images target "bench-build" { tags = ["frappe/bench:latest"] @@ -11,6 +15,9 @@ target "bench-test" { target = "test" } +# Main images +# Base for all other targets + target "frappe-nginx" { dockerfile = "build/frappe-nginx/Dockerfile" } @@ -41,35 +48,51 @@ target "develop-args" { } } -variable "GIT_TAG" {} -variable "GIT_BRANCH" {} -variable "VERSION" {} - -target "stable-args" { - args = { - GIT_BRANCH = "${GIT_BRANCH}" - IMAGE_TAG = "${GIT_BRANCH}" - PYTHON_VERSION = "${VERSION}" == "12" ? "3.7" : "3.9" - } -} - function "set_develop_tags" { params = [repo] result = ["${repo}:latest", "${repo}:edge", "${repo}:develop"] } +# NOTE: Variable are used only for stable builds +variable "GIT_TAG" {} # git tag, e.g. v13.15.0 +variable "GIT_BRANCH" {} # git branch, e.g. version-13 +variable "VERSION" {} # Frappe and ERPNext version, e.g. 13 + +target "stable-args" { + args = { + GIT_BRANCH = "${GIT_BRANCH}" + IMAGE_TAG = "${GIT_BRANCH}" + # ERPNext build fails on v12 + # TODO: Remove PYTHON_VERSION argument when v12 will stop being supported + PYTHON_VERSION = "${VERSION}" == "12" ? "3.7" : "3.9" + } +} + function "set_stable_tags" { + # e.g. base_image:v13.15.0, base_image:v13, base_image:version-13 params = [repo] result = ["${repo}:${GIT_TAG}", "${repo}:v${VERSION}", "${repo}:${GIT_BRANCH}"] } +target "test-erpnext-args" { + args = { + IMAGE_TAG = "test" + DOCKER_REGISTRY_PREFIX = "localhost:5000/frappe" + } +} + +function "set_local_test_tags" { + params = [repo] + result = ["localhost:5000/${repo}:test"] +} + function "set_test_tags" { params = [repo] result = ["${repo}:test"] } -# Develop +# Develop images target "frappe-nginx-develop" { inherits = ["frappe-nginx", "develop-args"] @@ -104,7 +127,22 @@ group "erpnext-develop" { targets = ["erpnext-nginx-develop", "erpnext-worker-develop"] } -# Develop test +# Test develop images + +target "frappe-nginx-develop-test-local" { + inherits = ["frappe-nginx-develop"] + tags = set_local_test_tags("frappe/frappe-nginx") +} + +target "frappe-worker-develop-test-local" { + inherits = ["frappe-worker-develop"] + tags = set_local_test_tags("frappe/frappe-worker") +} + +target "frappe-socketio-develop-test-local" { + inherits = ["frappe-socketio-develop"] + tags = set_local_test_tags("frappe/frappe-socketio") +} target "frappe-nginx-develop-test" { inherits = ["frappe-nginx-develop"] @@ -122,15 +160,19 @@ target "frappe-socketio-develop-test" { } target "erpnext-nginx-develop-test" { - inherits = ["erpnext-nginx-develop"] + inherits = ["erpnext-nginx-develop", "test-erpnext-args"] tags = set_test_tags("frappe/erpnext-nginx") } target "erpnext-worker-develop-test" { - inherits = ["erpnext-worker-develop"] + inherits = ["erpnext-worker-develop", "test-erpnext-args"] tags = set_test_tags("frappe/erpnext-worker") } +group "frappe-develop-test-local" { + targets = ["frappe-nginx-develop-test-local", "frappe-worker-develop-test-local", "frappe-socketio-develop-test-local"] +} + group "frappe-develop-test" { targets = ["frappe-nginx-develop-test", "frappe-worker-develop-test", "frappe-socketio-develop-test"] } @@ -140,7 +182,7 @@ group "erpnext-develop-test" { } -# Stable +# Stable images target "frappe-nginx-stable" { inherits = ["frappe-nginx", "stable-args"] @@ -175,7 +217,23 @@ group "erpnext-stable" { targets = ["erpnext-nginx-stable", "erpnext-worker-stable"] } -# Stable test +# Test stable images + +target "frappe-nginx-stable-test-local" { + inherits = ["frappe-nginx-stable"] + tags = set_local_test_tags("frappe/frappe-nginx") +} + +target "frappe-worker-stable-test-local" { + inherits = ["frappe-worker-stable"] + tags = set_local_test_tags("frappe/frappe-worker") +} + +target "frappe-socketio-stable-test-local" { + inherits = ["frappe-socketio-stable"] + tags = set_local_test_tags("frappe/frappe-socketio") +} + target "frappe-nginx-stable-test" { inherits = ["frappe-nginx-stable"] tags = set_test_tags("frappe/frappe-nginx") @@ -192,15 +250,19 @@ target "frappe-socketio-stable-test" { } target "erpnext-nginx-stable-test" { - inherits = ["erpnext-nginx-stable"] + inherits = ["erpnext-nginx-stable", "test-erpnext-args"] tags = set_test_tags("frappe/erpnext-nginx") } target "erpnext-worker-stable-test" { - inherits = ["erpnext-worker-stable"] + inherits = ["erpnext-worker-stable", "test-erpnext-args"] tags = set_test_tags("frappe/erpnext-worker") } +group "frappe-stable-test-local" { + targets = ["frappe-nginx-stable-test-local", "frappe-worker-stable-test-local", "frappe-socketio-stable-test-local"] +} + group "frappe-stable-test" { targets = ["frappe-nginx-stable-test", "frappe-worker-stable-test", "frappe-socketio-stable-test"] } diff --git a/tests/test-erpnext.sh b/tests/test-erpnext.sh index a22d999b..e2eb6902 100755 --- a/tests/test-erpnext.sh +++ b/tests/test-erpnext.sh @@ -9,21 +9,20 @@ SITE_NAME="test_erpnext.localhost" echo ::group::Setup env cp env-example .env -sed -i -e "s/FRAPPE_VERSION=edge/FRAPPE_VERSION=$FRAPPE_VERSION/g" .env -sed -i -e "s/ERPNEXT_VERSION=edge/ERPNEXT_VERSION=test/g" .env +sed -i -e "s/edge/test/g" .env # shellcheck disable=SC2046 export $(cat .env) cat .env print_group Start services -FRAPPE_VERSION=$FRAPPE_VERSION ERPNEXT_VERSION="test" \ - docker-compose \ +docker-compose \ -p $project_name \ -f installation/docker-compose-common.yml \ -f installation/docker-compose-erpnext.yml \ -f installation/erpnext-publish.yml \ up -d +print_group Fix permissions docker run \ --rm \ --user root \ diff --git a/tests/test-frappe.sh b/tests/test-frappe.sh index c28e0cfd..035aa2c9 100755 --- a/tests/test-frappe.sh +++ b/tests/test-frappe.sh @@ -7,6 +7,16 @@ source tests/functions.sh project_name="test_frappe" SITE_NAME="test_frappe.localhost" +docker_compose_with_args() { + # shellcheck disable=SC2068 + docker-compose \ + -p $project_name \ + -f installation/docker-compose-common.yml \ + -f installation/docker-compose-frappe.yml \ + -f installation/frappe-publish.yml \ + $@ +} + echo ::group::Setup env cp env-example .env sed -i -e "s/edge/test/g" .env @@ -15,13 +25,7 @@ export $(cat .env) cat .env print_group Start services -FRAPPE_VERSION="test" \ - docker-compose \ - -p $project_name \ - -f installation/docker-compose-common.yml \ - -f installation/docker-compose-frappe.yml \ - -f installation/frappe-publish.yml \ - up -d +docker_compose_with_args up -d print_group Create site docker run \ @@ -32,4 +36,8 @@ docker run \ frappe/frappe-worker:test new ping_site + +print_group Stop and remove containers +docker_compose_with_args down + rm .env