Skip to content

ci: use reusable vars HUB_BASE and IMAGE_LOCATION in workflow #197

ci: use reusable vars HUB_BASE and IMAGE_LOCATION in workflow

ci: use reusable vars HUB_BASE and IMAGE_LOCATION in workflow #197

Workflow file for this run

name: Unit Tests
on:
push:
branches:
- "[0-9]+.0"
paths:
- "**/workflows/**"
- "**/src/**"
- "**/i18n/**"
- "**.py"
- "**.xml"
pull_request:
branches:
- "[0-9]+.0"
paths:
- "**/workflows/**"
- "**/src/**"
- "**/i18n/**"
- "**.py"
- "**.xml"
types: [ opened, synchronize, reopened, labeled ]
env:
REQUIRED_MODULES: cloud_platform_exoscale # list of addional addons to install separated by comma
GAR_BASE: ${{ vars.GCP_REGISTRY}}
HUB_BASE: ${{ vars.HUB_BASE}}
IMAGE_LOCATION: ${{ vars.IMAGE_LOCATION}}
ENV: "test"
jobs:
build:
name: Build
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
outputs:
get_modules: ${{ steps.get_modules.outputs.modules }}
image_digest: ${{ steps.docker_build.outputs.digest }}
steps:
### Dependencies
- uses: rlespinasse/[email protected]
- name: Checkout local
uses: actions/checkout@v2
with:
path: ${{ env.GITHUB_REPOSITORY_SLUG_URL }}
- name: Odoo Enterprise
uses: actions/checkout@v2
with:
repository: ${{ vars.REPOSITORY_NAME }}
token: ${{ secrets.ACTIONS_PAT }}
path: ${{ vars.REPOSITORY_NAME }}
ref: ${{ env.GITHUB_BASE_REF_SLUG }}
# - name: Odoo Themes
# uses: actions/checkout@v2
# with:
# repository: opticrd/odoo-website-themes
# token: ${{ secrets.ACTIONS_PAT }}
# path: odoo/themes
# ref: ${{ env.GITHUB_BASE_REF_SLUG }}
- name: Select Odoo modules to install
id: get_modules
run: |
curl https://raw.githubusercontent.com/iterativo-git/dockerdoo/${{ env.GITHUB_BASE_REF_SLUG }}/resources/getaddons.py -o getaddons.py
output=$(python -c "from getaddons import get_modules; print(','.join(get_modules('./${{ env.GITHUB_REPOSITORY_SLUG_URL }}', depth=3)))")
echo "::set-output name=modules::$output"
### Build the Docker image and Push it
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
with:
driver-opts: network=host
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: |
/tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.GITHUB_HEAD_REF_SLUG }}-${{ env.GITHUB_SHA_SHORT }}
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GKE_SA_KEY }}
- name: Set env to integration
if: ${{ github.event.label.name == 'staging' }}
run: |
echo "ENV=integration" >> $GITHUB_ENV
- name: Build & push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
file: ./${{ env.GITHUB_REPOSITORY_SLUG_URL }}/Dockerfile
tags: ${{ env.GAR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:${{ env.GITHUB_HEAD_REF_SLUG }}
build-args: |
RUNNING_ENV=${{ env.ENV }}
EXTRA_MODULES=${{ steps.get_modules.outputs.modules }},${{ env.REQUIRED_MODULES }}
IMAGE_LOCATION=${{ env.IMAGE_LOCATION }}
ODOO_VERSION=${{ env.GITHUB_BASE_REF_SLUG }}
PGHOST=${{ secrets.DB_PORT_5432_TCP_ADDR_15 }}
PGUSER=${{ secrets.DB_ENV_POSTGRES_USER }}
PGPORT=${{ secrets.DB_PORT_5432_TCP_PORT }}
PGPASSWORD=${{ secrets.DB_ENV_POSTGRES_PASSWORD }}
ODOO_SESSION_REDIS=${{ secrets.ODOO_SESSION_REDIS }}
ODOO_SESSION_REDIS_HOST=${{ secrets.ODOO_SESSION_REDIS_HOST }}
ODOO_SESSION_REDIS_PREFIX=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-odoo-${{ env.ENV }}
ODOO_LOGGING_JSON=${{ secrets.ODOO_LOGGING_JSON }}
AWS_HOST=${{ secrets.AWS_HOST }}
AWS_REGION=${{ secrets.AWS_REGION }}
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_BUCKETNAME=${{ secrets.AWS_BUCKETNAME }}
AWS_BUCKETNAME_UNSTRUCTURED=true
DBNAME=${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_HEAD_REF_SLUG_URL }}.${{ secrets.ROOT_DOMAIN }}
SERVER_WIDE_MODULES=base,web,session_redis,logging_json,attachment_s3
DBFILTER=False
push: true
cache-from: type=registry,ref=${{ env.GAR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:${{ env.GITHUB_HEAD_REF_SLUG }}
cache-to: type=inline
# Download artifact with db name
- name: Download artifact with database name
if: ${{ github.event.label.name == 'staging' }}
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: staging.yaml
name: db_name-${{ env.GITHUB_HEAD_REF_SLUG }}
- name: Set env with database name
if: ${{ github.event.label.name == 'staging' }}
run: echo "Setting database env variable..."
env:
DB_NAME: $(cat db_name.txt)
### Set up Kustomize and build it
- name: K8s Template
uses: actions/checkout@v2
with:
repository: ${{ env.GITHUB_REPOSITORY_OWNER_PART_SLUG }}/odoo-kubernetes-infra
path: gke-dev-cluster
token: ${{ secrets.ACTIONS_PAT }}
ref: main
- uses: imranismail/setup-kustomize@v1
with:
kustomize-version: "3.1.0"
- run: kustomize build gke-dev-cluster/deployments/odoo/${{ env.ENV }} -o deployment.yaml.tmpl
- name: Render Deployment YAML
uses: nowactions/envsubst@v1
with:
input: ./deployment.yaml.tmpl
output: ./deployment.yaml
env:
ENV: ${{ env.ENV }}
GKE_LOCATION: ${{ secrets.GKE_ZONE }}
# Modules to Install
EXTRA_MODULES: ${{ steps.get_modules.outputs.modules }},${{ env.REQUIRED_MODULES }}
# Image to Deploy
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
REPO_NAME: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}
BRANCH_NAME: ${{ env.GITHUB_HEAD_REF_SLUG }}
ODOO_VERSION: ${{ env.GITHUB_BASE_REF_SLUG }}
DEPLOY_IMAGE: ${{ env.GAR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}@${{ steps.docker_build.outputs.digest }}
# URL to acccess
REPO_URL: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}
BRANCH_URL: ${{ env.GITHUB_HEAD_REF_SLUG_URL }}
SHORT_SHA: ${{ env.GITHUB_SHA_SHORT }}
STAGING_DB: ${{ env.DB_NAME }}
ODOO_VERSION_URL_SLUG: ${{ env.GITHUB_BASE_REF_SLUG_URL }}
DEPLOY_DOMAIN: ${{ secrets.DEPLOY_DOMAIN }}
- uses: actions/upload-artifact@v4
with:
name: deployment-${{ env.GITHUB_HEAD_REF_SLUG }}
path: deployment.yaml
- name: Comment to trigger deploy
if: ${{ github.event.label.name == 'staging' }}
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.number }}
token: ${{ secrets.ACTIONS_PAT }}
body: |
/deploy
reactions: hooray
test:
name: Test Modules
needs: ["build"]
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.label.name != 'staging' }}
services:
db:
image: postgres:12-alpine
env:
POSTGRES_DB: postgres
POSTGRES_USER: ${{ secrets.DB_ENV_POSTGRES_USER }}
POSTGRES_PASSWORD: ${{ secrets.DB_ENV_POSTGRES_PASSWORD }}
# needed because the postgres container does not provide a healthcheck
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: rlespinasse/[email protected]
- name: Login to GAR
uses: docker/login-action@v1
with:
registry: us-docker.pkg.dev
username: _json_key
password: ${{ secrets.GKE_SA_KEY }}
- name: Run Odoo tests
run: |
docker pull ${{ env.GAR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:${{ env.GITHUB_HEAD_REF_SLUG }}
docker run -e RUN_TESTS -e LOG_LEVEL -e EXTRA_MODULES -e PGHOST --network="host" --name odoo -t ${{ env.GAR_BASE }}/${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG }}:${{ env.GITHUB_HEAD_REF_SLUG }}
env:
RUN_TESTS: "1"
LOG_LEVEL: test
EXTRA_MODULES: ${{ needs.build.outputs.get_modules }}
TEST_DB: ${{ env.GITHUB_REPOSITORY_NAME_PART_SLUG_URL }}-${{ env.GITHUB_HEAD_REF_SLUG_URL }}.${{ secrets.DEPLOY_DOMAIN }}
PGHOST: localhost
PGUSER: ${{ secrets.DB_ENV_POSTGRES_USER }}
PGPASSWORD: ${{ secrets.DB_ENV_POSTGRES_PASSWORD }}