From 642637e81ece5576cf3726ebad7f8993f2cc29ab Mon Sep 17 00:00:00 2001 From: Lea Vauchier Date: Wed, 7 Aug 2024 16:43:08 +0200 Subject: [PATCH] Deploy docker image on ghcr.io --- .github/workflows/cicd_deploy.yml | 76 +++++++++++++++++++++---------- CHANGELOG.md | 4 ++ coclico/version.py | 2 +- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/.github/workflows/cicd_deploy.yml b/.github/workflows/cicd_deploy.yml index 1fe1315..a781dc4 100644 --- a/.github/workflows/cicd_deploy.yml +++ b/.github/workflows/cicd_deploy.yml @@ -2,12 +2,15 @@ name: cicd_deploy on: push: - # Run deployment on every new tag - tags: - - '*' + # Run deployment on every new version tag and every push to main + branches: [ "main" ] + tags: [ '*.*.*' ] env: - DOCKER_REPO: ignimagelidar/coclico + IMAGE_NAME: ${{ github.repository }} + REGISTRY: ghcr.io + DOCKER_IMAGE_NAME: coclico + TEST_TAG: coclico:test jobs: deploy_docker: @@ -15,39 +18,64 @@ jobs: steps: - name: Checkout branch - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Login to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Build and export to Docker - uses: docker/build-push-action@v4 + # build the image + - name: Build Docker image for tests + id: build + uses: docker/build-push-action@v5 with: - context: . load: true - tags: ${{ env.DOCKER_REPO }}:test + tags: ${{ env.TEST_TAG }} - name: Run tests in docker run: > docker run --ipc=host - ${{ env.DOCKER_REPO }}:test + ${{ env.TEST_TAG }} python -m pytest -m docker -s --log-cli-level DEBUG - name: Set version number run: | - echo "VERSION=$(python -m coclico.version)" >> $GITHUB_ENV + echo "VERSION=v$(python -m coclico.version)" >> $GITHUB_ENV + + - name: Check tag and version number consistency + if: ${{ github.event_name == 'tag' }} + run: | + if [[ ${{ github.ref_name }} == ${{ env.VERSION }} ]] + then + echo "OK: Tag name and VERSION.md (${{ env.VERSION }}) version number (${{ github.ref_name }}) match" + else + echo "NOK: Tag name and VERSION.md (${{ env.VERSION }}) version number (${{ github.ref_name }}) don't match" + exit 1 + fi - - name: Build and push - uses: docker/build-push-action@v4 + # 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@v2 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + if: ${{ github.event_name != 'pull_request' }} + uses: docker/build-push-action@v5 with: context: . push: true - tags: ${{ env.DOCKER_REPO }}:latest,${{ env.DOCKER_REPO }}:${{ env.VERSION }} - + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index b31e2e3..b004b7e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.1.1 + +- L'image docker est maintenant stockée sur ghcr.io + # 1.1.0 - MOBJ0 : Utilisation de la 4-connexité au lieu de 8-connexité pour la génération des formes à partir de la carte diff --git a/coclico/version.py b/coclico/version.py index b75bb55..ecb2274 100644 --- a/coclico/version.py +++ b/coclico/version.py @@ -1,4 +1,4 @@ -__version__ = "1.1.0" +__version__ = "1.1.1" if __name__ == "__main__":