Kaynağa Gözat

workflows: build joystream/node image only if modified

Mokhtar Naamani 4 yıl önce
ebeveyn
işleme
38c47eae39

+ 28 - 10
.github/workflows/run-network-tests.yml

@@ -14,19 +14,37 @@ jobs:
       - uses: actions/setup-node@v1
         with:
           node-version: '12.x'
+      - uses: technote-space/get-diff-action@v3
+        with:
+          PREFIX_FILTER: |
+            node
+            runtime-modules
+            utils/chain-spec-builder
+          SUFFIX_FILTER: |
+            .rs
+          FILES: |
+            Cargo.lock
+            Cargo.toml
       - name: Install packages and dependencies
         run: yarn install --frozen-lockfile
       - name: Ensure tests are runnable
         run: yarn workspace network-tests build
-      # TODO: determin if we will build a new joystream/node image from source
-      # our use a prebuilt image. Build if PR has joystream-node or runtime code changes
-      # For prebuilt image set NODE_TAG env var to select tag. Use the PR base branch, 
-      # ie. the 'target' branch of the PR. For now we just use hardcoded the pre-built image
-      # defined in the docker-compose file.
-      # When building from source tweak the block production setting for faster tests.
-      # - name: Configuring shorter block production time
-      #   run: ./scripts/alter-block-creation-time.sh
-      - name: Build and start chain
-        run: docker-compose --file docker-compose-no-build.yml up -d
+      - name: Maybe fetch pre-build joystream/node image 
+          run: |
+            # Always configure faster block production incase pull fails.
+            ./scripts/alter-block-creation-time.sh
+            export JOYSTREAM_NODE_TAG="${{ pull.base.ref }}""
+            echo "DEBUG: JOYSTREAM_NODE_TAG = ${JOYSTREAM_NODE_TAG}"
+            if [ "${{ env.GIT_DIFF }}" ]
+            then
+              echo "Will build joystream-node from source."
+            else
+              # Try to get image tagged with base branch name. If it fails we continue anyway,
+              # docker-compose will then bulid from srouce when it doesn't find the image.
+              echo "Trying to pull from docker hub..."
+              docker pull joystream/node:${JOYSTREAM_NODE_TAG}
+            fi
+      - name: Start chain
+        run: JOYSTREAM_NODE_TAG=${{ pull.base.ref }} docker-compose up -d
       - name: Execute network tests
         run: yarn workspace network-tests test

+ 0 - 14
docker-compose-no-build.yml

@@ -1,14 +0,0 @@
-# Run joystream local development chain
-# Will use an local image if found, otherwise image will be pulled from:
-# https://hub.docker.com/r/joystream/node
-version: "3"
-services:
-  node:
-    # TODO: make the tag come from env variable
-    # image: joystream/node:${NODE_TAG}
-    image: joystream/node:babylon
-    container_name: joystream-node
-    command: --dev --alice --validator --unsafe-ws-external --rpc-cors=all
-    ports:
-      - "9944:9944"
-  

+ 1 - 1
docker-compose.yml

@@ -4,7 +4,7 @@
 version: "3"
 services:
   joystream-node:
-    image: joystream/node
+    image: "joystream/node:${JOYSTREAM_NODE_TAG}"
     build:
       # context is relative to the compose file
       context: .