From b88fe89178f95bb400ecf79b92a242fd99be4ea7 Mon Sep 17 00:00:00 2001 From: fnecas Date: Tue, 30 Jan 2024 10:18:09 +0100 Subject: [PATCH] feat: CI ready --- .github/workflows/ci.yml | 35 ++++++++++++++++++++--------------- apps/datahub/project.json | 4 ++-- tools/print-docker-tag.sh | 16 ---------------- 3 files changed, 22 insertions(+), 33 deletions(-) delete mode 100755 tools/print-docker-tag.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99d99845..a158b850 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ on: permissions: actions: read contents: read + packages: write jobs: lint-test-build: @@ -30,33 +31,37 @@ jobs: npx nx affected --target=test --parallel=3 --ci --code-coverage npx nx affected --target=build --parallel=3 - build-docker: + push-docker: needs: lint-test-build name: Build and upload docker image and archive runs-on: ubuntu-latest steps: - - name: Build datahub and produce archives - if: github.event_name == 'release' - run: | - npx nx run-many --projects=datahub --target=build + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ env.NODE_VERSION }} + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + + - name: Install dependencies + run: npm i + + - name: Run docker-build + run: npx nx docker-build datahub - uses: docker/login-action@v1 name: Login to GitHub Container Registry with: registry: ghcr.io - username: c2c-bot-gis-ci - password: ${{ secrets.GOPASS_CI_GITHUB_TOKEN }} - - - name: Setting image tag - id: version - run: echo ::set-output name=VERSION::$(echo $GITHUB_REF | cut -d / -f 3) + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: "Pushing the image onto ghcr.io" + - name: 'Pushing the image onto ghcr.io' + if: github.ref == 'refs/heads/main' run: | - docker image ls --format '{{.Repository}}:{{.Tag}}' --filter=reference='ghcr.io/camptocamp/mel-dataplatform/*' | \ - xargs -r -L1 docker push $1 - + docker push ghcr.io/camptocamp/mel-dataplatform/datahub:latest cypress-run: name: End-to-end tests diff --git a/apps/datahub/project.json b/apps/datahub/project.json index cac095ee..c52e6929 100644 --- a/apps/datahub/project.json +++ b/apps/datahub/project.json @@ -98,8 +98,8 @@ "executor": "nx:run-commands", "options": { "commands": [ - "nx build datahub --base-href='/datahub/'", - "docker build --build-arg APP_NAME=datahub -f ./tools/docker/Dockerfile . -t $(tools/print-docker-tag.sh datahub) -t ghcr.io/camptocamp/mel-dataplatform/datahub:latest" + "nx build datahub", + "docker build --build-arg APP_NAME=datahub -f ./tools/docker/Dockerfile . -t ghcr.io/camptocamp/mel-dataplatform/datahub:latest" ], "parallel": false } diff --git a/tools/print-docker-tag.sh b/tools/print-docker-tag.sh deleted file mode 100755 index 264c8f5c..00000000 --- a/tools/print-docker-tag.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -# Will print a docker tag with a version based on the current git branch and tag -# e.g.: geonetwork/geonetwork-ui-my-app:1.0.0-RC2 -# or: geonetwork/geonetwork-ui-my-app:feature-branch - -appName=$1 -gitTag=$(git describe --exact-match --tags 2>/dev/null | sed "s/^v//") # remove "v" in front of version if any -gitBranch=$(git symbolic-ref --short HEAD) -gitRef=$(git rev-parse --short HEAD) -dockerTag=${gitTag:-${gitBranch}} -if [ ${dockerTag} == "main" ]; then - dockerTag=${dockerTag}-${gitRef} -fi - -echo "ghcr.io/camptocamp/mel-dataplatform/${appName}:${dockerTag}"