Skip to content

Commit

Permalink
[ADD] workflow first approach
Browse files Browse the repository at this point in the history
  • Loading branch information
az-adhoc committed Jan 11, 2025
1 parent 94b15f1 commit 9c08e21
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 84 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.devcontainer
.hooks
README.MD
.github
131 changes: 131 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: build

on:
workflow_dispatch:
inputs:
odoo_target:
description: "Odoo Version"
required: true
type: choice
options:
- "18.0"
default: "18.0"

repository_dispatch:
types:
- webhook

concurrency:
# Gruop by Odoo Version
group: ${{ github.event.inputs.odoo_target || github.event.client_payload.odoo_target }}
cancel-in-progress: true

jobs:

geoip:
name: GeoIp
runs-on: ubuntu-latest
env:
MAXMIND_LICENSE_USR: ${{ secrets.MAXMIND_LICENSE_USR }}
MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }}
outputs:
last-modified: ${{ steps.get-last-modified.outputs.last-modified }}

steps:
- name: Check if GeoIP has any update
id: get-last-modified
run: |
MAXMIND_UPDATE=$(curl -I -sL -u ${MAXMIND_LICENSE_USR}:${MAXMIND_LICENSE_KEY} 'https://download.maxmind.com/geoip/databases/GeoLite2-City/download?suffix=tar.gz' | grep -i 'Last-Modified')
MAXMIND_UPDATE=${MAXMIND_UPDATE#*: }
MAXMIND_UPDATE=$(date -d "$MAXMIND_UPDATE" +"%Y%m%d%H%M%S")
echo "last-modified=$MAXMIND_UPDATE" >> $GITHUB_OUTPUT
build:
name: Build
runs-on: ubuntu-latest
needs:
- geoip
env:
ODOO_TARGET: ${{ github.event.inputs.odoo_target || github.event.client_payload.odoo_target }}
ODOO_BUILD: 0
ODOO_BY_ADHOC_BUILD: 0
MAXMIND_GEOIP_UPDATE: ${{ needs.geoip.outputs.last-modified }}
# MAXMIND_LICENSE_USR: ${{ secrets.MAXMIND_LICENSE_USR }}
# MAXMIND_LICENSE_KEY: ${{ secrets.MAXMIND_LICENSE_KEY }}
# GITHUB_BOT_TOKEN: ${{ secrets.BOT_TOKEN_GITHUB }}

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Get odoo build
id: get-odoo-build
run: echo "date=$(/bin/date -u "+%Y%m")" >> $GITHUB_OUTPUT

- name: Get odoo build
id: get-odoo-adhoc-build
run: echo "date=$(/bin/date -u "+%Y.%m.%d")" >> $GITHUB_OUTPUT

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# Login to Docker Hub (for pushing the final image)
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

# Build lower layers
# TODO: Upload odoo version.
- name: Build dev
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
push: true
build-args: |
MAXMIND_LICENSE_USER=${{ secrets.MAXMIND_LICENSE_USR }}
MAXMIND_LICENSE_KEY=${{ secrets.MAXMIND_LICENSE_KEY }}
MAXMIND_UPDATE=${{ env.MAXMIND_UPDATE }}
ODOO_VERSION=${{ env.ODOO_TARGET }}
ODOO_BUILD=${{ steps.get-odoo-build.outputs.date }}
SAAS_PROVIDER_URL=${{ secrets.SAAS_PROVIDER_URL }}
SAAS_PROVIDER_TOKEN=${{ secrets.SAAS_PROVIDER_TOKEN }}
GITHUB_BOT_TOKEN=${{ secrets.BOT_TOKEN_GITHUB }}
ODOO_BY_ADHOC_BUILD=${{ steps.get-odoo-adhoc-build.outputs.date }}.${{ github.run_number }}
# Force to recreate this layer (this is no longer needed due the ODOO_BY_ADHOC_BUILD)
# no-cache-filters: aggregate-source
target: dev
tags: |
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next.${{ steps.get-odoo-adhoc-build.outputs.date }}.${{ github.run_number }}.dev
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next.${{ steps.get-odoo-adhoc-build.outputs.date }}.dev
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next.dev
- name: Build prod
uses: docker/build-push-action@v6
with:
cache-from: type=gha
cache-to: type=gha,mode=max
context: .
push: true
build-args: |
MAXMIND_LICENSE_USER=${{ secrets.MAXMIND_LICENSE_USR }}
MAXMIND_LICENSE_KEY=${{ secrets.MAXMIND_LICENSE_KEY }}
MAXMIND_UPDATE=${{ env.MAXMIND_UPDATE }}
ODOO_VERSION=${{ env.ODOO_TARGET }}
ODOO_BUILD=${{ steps.get-odoo-build.outputs.date }}
SAAS_PROVIDER_URL=${{ secrets.SAAS_PROVIDER_URL }}
SAAS_PROVIDER_TOKEN=${{ secrets.SAAS_PROVIDER_TOKEN }}
GITHUB_BOT_TOKEN=${{ secrets.BOT_TOKEN_GITHUB }}
ODOO_BY_ADHOC_BUILD=${{ steps.get-odoo-adhoc-build.outputs.date }}.${{ github.run_number }}
target: prod
tags: |
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next.${{ steps.get-odoo-adhoc-build.outputs.date }}.${{ github.run_number }}
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next.${{ steps.get-odoo-adhoc-build.outputs.date }}
docker.io/adhoc/odoo-adhoc:${{ env.ODOO_TARGET }}.next
43 changes: 43 additions & 0 deletions .github/workflows/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Workflows

## Act

[Download](https://github.com/nektos/act/releases/latest/download/act_Linux_x86_64.tar.gz)

## Secrets

### Github

GITHUB_TOKEN

required permissions:

- write on ghcr.io

### Docker hub

Used to upload the final images

DOCKER_USERNAME=
DOCKER_PASSWORD=

### GeoIP

MAXMIND_LICENSE_USR=
MAXMIND_LICENSE_KEY=

### GITHUB_BOT

BOT_TOKEN_GITHUB

required permissions:

- read repositories (dev-adhoc and ingadhoc)

### GITHUB REGISTRY

TOKEN_GH_REGISTRY

required permissions:

- r/w/d package
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
BuildNotes.md
BuildNotes.md
act
act_ctx
Loading

0 comments on commit 9c08e21

Please sign in to comment.