Skip to content

Commit

Permalink
ci: Use GitHub Actions to build images
Browse files Browse the repository at this point in the history
  • Loading branch information
vrslev committed Oct 27, 2021
1 parent c149a93 commit 1cbb845
Show file tree
Hide file tree
Showing 8 changed files with 338 additions and 339 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: daily
5 changes: 5 additions & 0 deletions .github/scripts/get-latest-tag.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

TAGS=$(git ls-remote --refs --tags --sort='v:refname' https://github.com/$REPO "v$VERSION.*")
TAG=$(echo $TAGS | tail -n1 | sed 's/.*\///')
echo $TAG
193 changes: 193 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
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
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push
uses: docker/[email protected]
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
# 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/[email protected]
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/[email protected]
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
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/[email protected]
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/[email protected]
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'
run: |
export GIT_SSH_COMMAND="ssh -i ${PWD}/deploy_key"
echo "$HELM_DEPLOY_KEY" | openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -out deploy_key -d
chmod 400 deploy_key;
ssh-keyscan github.com >> $HOME/.ssh/known_hosts 2>/dev/null;
pip install --upgrade pip
git clone [email protected]:frappe/helm.git && cd helm
pip install -r release_wizard/requirements.txt
./release_wizard/wizard 13 patch --remote origin --ci
env:
HELM_DEPLOY_KEY: ${{ secrets.HELM_DEPLOY_KEY }}
187 changes: 0 additions & 187 deletions .travis.yml

This file was deleted.

Loading

0 comments on commit 1cbb845

Please sign in to comment.