Create v16 config #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Push Odoo Dev Container | |
on: | |
push: | |
paths: | |
- '.devcontainer/URL.conf' | |
workflow_dispatch: | |
env: | |
# Use docker.io for Docker Hub if empty | |
REGISTRY: ghcr.io | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
# This is used to complete the identity challenge | |
# with sigstore/fulcio when running outside of PRs. | |
id-token: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
# Set up BuildKit Docker container builder to be able to build | |
# multi-platform images and export cache | |
# https://github.com/docker/setup-buildx-action | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 | |
# Login against a Docker registry except on PR | |
# https://github.com/docker/login-action | |
- name: Log into registry ${{ env.REGISTRY }} | |
if: github.event_name != 'pull_request' | |
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
# Download .deb package with curl from the provided URL in the ./devcontainer/URL.txt file | |
- name: Download odoo.deb package | |
if: github.event_name != 'pull_request' | |
run: | | |
curl -sSL -o .devcontainer/odoo.deb $(cat .devcontainer/URL.conf) | |
# Set environmet variables based on the downloaded .deb package version number | |
- name: Set Odoo version environment variable | |
if: github.event_name != 'pull_request' | |
run: | | |
export ODOO_DEB_VERSION=$(dpkg-deb -f .devcontainer/odoo.deb version) | |
echo "ODOO_DEB_VERSION=${ODOO_DEB_VERSION}" >> $GITHUB_ENV | |
echo "ODOO_MAIN_VERSION=${ODOO_DEB_VERSION:0:2}" >> $GITHUB_ENV | |
echo "ODOO_TYPE=$(echo $ODOO_DEB_VERSION | grep -q 'e' && echo 'enterprise' || echo 'community')" >> $GITHUB_ENV | |
# Use the tag 'latest' only if the downloaded .deb package is for the Enterprise version (Enterprise download URL only provides the latest build) | |
# or if the download URL includes the word 'latest' (for Community version you can use either latest or any specific date) | |
- name: Determine if latest tag should be used | |
if: github.event_name != 'pull_request' | |
run: | | |
if [[ "${{ env.ODOO_TYPE }}" == "enterprise" ]] || grep -q 'latest' .devcontainer/URL.conf; then | |
echo "IS_LATEST=true" >> $GITHUB_ENV | |
else | |
echo "IS_LATEST=false" >> $GITHUB_ENV | |
fi | |
# Extract metadata (tags, labels) for Docker | |
# https://github.com/docker/metadata-action | |
- name: Extract Docker metadata | |
if: ${{ github.event_name != 'pull_request' }} | |
id: meta | |
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 | |
with: | |
images: ${{ env.REGISTRY }}/${{ github.actor }}/odoo-v${{ env.ODOO_MAIN_VERSION }}-${{ env.ODOO_TYPE }} | |
tags: | | |
type=raw,value=${{ env.ODOO_DEB_VERSION }} | |
type=raw,value=latest,enable=${{ env.IS_LATEST }} | |
# Build and push Docker image with Buildx (don't push on PR) | |
# https://github.com/docker/build-push-action | |
- name: Build and push Docker image | |
if: ${{ github.event_name != 'pull_request' }} | |
id: build-and-push | |
uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 | |
with: | |
context: ./.devcontainer | |
file: ./.devcontainer/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |