|
| 1 | +name: Build and Push Odoo Dev Container |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + paths: |
| 6 | + - '.devcontainer/URL.conf' |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +env: |
| 10 | + # Use docker.io for Docker Hub if empty |
| 11 | + REGISTRY: ghcr.io |
| 12 | + |
| 13 | + |
| 14 | +jobs: |
| 15 | + build: |
| 16 | + |
| 17 | + runs-on: ubuntu-latest |
| 18 | + permissions: |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + # This is used to complete the identity challenge |
| 22 | + # with sigstore/fulcio when running outside of PRs. |
| 23 | + id-token: write |
| 24 | + |
| 25 | + steps: |
| 26 | + - name: Checkout repository |
| 27 | + uses: actions/checkout@v3 |
| 28 | + |
| 29 | + # Set up BuildKit Docker container builder to be able to build |
| 30 | + # multi-platform images and export cache |
| 31 | + # https://github.com/docker/setup-buildx-action |
| 32 | + - name: Set up Docker Buildx |
| 33 | + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 |
| 34 | + |
| 35 | + # Login against a Docker registry except on PR |
| 36 | + # https://github.com/docker/login-action |
| 37 | + - name: Log into registry ${{ env.REGISTRY }} |
| 38 | + if: github.event_name != 'pull_request' |
| 39 | + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 |
| 40 | + with: |
| 41 | + registry: ${{ env.REGISTRY }} |
| 42 | + username: ${{ github.actor }} |
| 43 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + |
| 45 | + # Download .deb package with curl from the provided URL in the ./devcontainer/URL.txt file |
| 46 | + - name: Download odoo.deb package |
| 47 | + if: github.event_name != 'pull_request' |
| 48 | + run: | |
| 49 | + curl -sSL -o .devcontainer/odoo.deb $(cat .devcontainer/URL.conf) |
| 50 | +
|
| 51 | + # Set environmet variables based on the downloaded .deb package version number |
| 52 | + - name: Set Odoo version environment variable |
| 53 | + if: github.event_name != 'pull_request' |
| 54 | + run: | |
| 55 | + export ODOO_DEB_VERSION=$(dpkg-deb -f .devcontainer/odoo.deb version) |
| 56 | + echo "ODOO_DEB_VERSION=${ODOO_DEB_VERSION}" >> $GITHUB_ENV |
| 57 | + echo "ODOO_MAIN_VERSION=${ODOO_DEB_VERSION:0:2}" >> $GITHUB_ENV |
| 58 | + echo "ODOO_TYPE=$(echo $ODOO_DEB_VERSION | grep -q 'e' && echo 'enterprise' || echo 'community')" >> $GITHUB_ENV |
| 59 | +
|
| 60 | + # Use the tag 'latest' only if the downloaded .deb package is for the Enterprise version (Enterprise download URL only provides the latest build) |
| 61 | + # or if the download URL includes the word 'latest' (for Community version you can use either latest or any specific date) |
| 62 | + - name: Determine if latest tag should be used |
| 63 | + if: github.event_name != 'pull_request' |
| 64 | + run: | |
| 65 | + if [[ "${{ env.ODOO_TYPE }}" == "enterprise" ]] || grep -q 'latest' .devcontainer/URL.conf; then |
| 66 | + echo "IS_LATEST=true" >> $GITHUB_ENV |
| 67 | + else |
| 68 | + echo "IS_LATEST=false" >> $GITHUB_ENV |
| 69 | + fi |
| 70 | +
|
| 71 | + # Extract metadata (tags, labels) for Docker |
| 72 | + # https://github.com/docker/metadata-action |
| 73 | + - name: Extract Docker metadata |
| 74 | + if: ${{ github.event_name != 'pull_request' }} |
| 75 | + id: meta |
| 76 | + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 |
| 77 | + with: |
| 78 | + images: ${{ env.REGISTRY }}/${{ github.actor }}/odoo-v${{ env.ODOO_MAIN_VERSION }}-${{ env.ODOO_TYPE }} |
| 79 | + tags: | |
| 80 | + type=raw,value=${{ env.ODOO_DEB_VERSION }} |
| 81 | + type=raw,value=latest,enable=${{ env.IS_LATEST }} |
| 82 | +
|
| 83 | + # Build and push Docker image with Buildx (don't push on PR) |
| 84 | + # https://github.com/docker/build-push-action |
| 85 | + - name: Build and push Docker image |
| 86 | + if: ${{ github.event_name != 'pull_request' }} |
| 87 | + id: build-and-push |
| 88 | + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 |
| 89 | + with: |
| 90 | + context: ./.devcontainer |
| 91 | + file: ./.devcontainer/Dockerfile |
| 92 | + push: true |
| 93 | + tags: ${{ steps.meta.outputs.tags }} |
| 94 | + labels: ${{ steps.meta.outputs.labels }} |
| 95 | + cache-from: type=gha |
| 96 | + cache-to: type=gha,mode=max |
0 commit comments