Browse Source

Automatically publish Docker image (#764)

Danilo Bargen 6 năm trước cách đây
mục cha
commit
731dd53b19
4 tập tin đã thay đổi với 107 bổ sung19 xóa
  1. 57 19
      .circleci/config.yml
  2. 1 0
      .dockerignore
  3. 4 0
      RELEASING.md
  4. 45 0
      docker/rebuild.sh

+ 57 - 19
.circleci/config.yml

@@ -44,37 +44,55 @@ jobs:
     environment:
       BUILDTARGET: build:uitests
       TESTTARGET: test:ui chrome
-  dist:
+  lint:
     docker:
-      - image: circleci/node:10-browsers
+      - image: circleci/node:8-browsers
     steps:
       - checkout
       - restore_cache:
           keys:
-            - v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "package.json" }}
-      - run: npm install --release
-      - run: npm run dist
-      - save_cache:
-          key: v2-dependencies-{{ .Environment.CIRCLE_JOB }}-{{ arch }}-{{ checksum "package.json" }}
-          paths:
-            - node_modules
+            - v2-dependencies-test-node8-{{ arch }}-{{ checksum "package.json" }}
+      - run: npm install
+      - run: npm run lint
   docker-build:
     docker:
       - image: docker:stable
     steps:
       - checkout
       - setup_remote_docker
-      - run: docker build . --no-cache -t threema/threema-web:${CIRCLE_BRANCH}
-  lint:
+      - run: docker build . --no-cache
+  docker-push-branch:
     docker:
-      - image: circleci/node:8-browsers
+      - image: docker:stable
     steps:
       - checkout
-      - restore_cache:
-          keys:
-            - v2-dependencies-test-node8-{{ arch }}-{{ checksum "package.json" }}
-      - run: npm install
-      - run: npm run lint
+      - setup_remote_docker
+      - run: >
+          docker build .  --no-cache -t threema/threema-web:${CIRCLE_BRANCH}
+          && docker login -u $DOCKER_USER -p $DOCKER_API_KEY
+          && docker push threema/threema-web
+  docker-push-tag:
+    docker:
+      - image: docker:stable
+    environment:
+      IMAGE: threema/threema-web
+    steps:
+      - checkout
+      - setup_remote_docker
+      - run: >
+          export minortag=$(echo $CIRCLE_TAG | sed 's/^\(v[0-9]*\.[0-9]*\)\..*$/\1/')
+                 majortag=$(echo $CIRCLE_TAG | sed 's/^\(v[0-9]*\)\..*$/\1/')
+          && docker build .  --no-cache -t $IMAGE:$CIRCLE_TAG -t $IMAGE:$minortag -t $IMAGE:$majortag
+          && docker login -u $DOCKER_USER -p $DOCKER_API_KEY
+          && docker push threema/threema-web
+  docker-rebuild-images:
+    docker:
+      - image: docker:stable
+    steps:
+      - checkout
+      - setup_remote_docker
+      - run: bash docker/rebuild.sh
+
 
 workflows:
   version: 2
@@ -84,6 +102,26 @@ workflows:
       - unittest-node10
       - uitest-firefox
       - uitest-chrome
-      - dist
       - lint
-      - docker-build
+      - docker-build:
+          filters:
+            branches:
+              ignore: master
+      - docker-push-branch:
+          filters:
+            branches:
+              only: master
+      - docker-push-tag:
+          filters:
+            branches:
+              only: /v[0-9.]*/
+  weekly:
+    triggers:
+      - schedule:
+          cron: "45 14 * * 4"
+          filters:
+            branches:
+              only:
+                - master
+    jobs:
+      - docker-rebuild-images

+ 1 - 0
.dockerignore

@@ -3,3 +3,4 @@ node_modules/
 build/
 release/
 dist/*.tar.gz
+docker/rebuild.sh

+ 4 - 0
RELEASING.md

@@ -23,6 +23,10 @@ Update changelog:
 
     $ vim CHANGELOG.md
 
+Potentially update `SUPPORTED_TAG_PATTERNS` in `docker/rebuild.sh`:
+
+    $ vim docker/rebuild.sh
+
 Commit & tag:
 
     $ git commit -S${GPG_KEY} -m "Release v${VERSION}"

+ 45 - 0
docker/rebuild.sh

@@ -0,0 +1,45 @@
+#!/bin/bash
+#
+# Rebuild and publish all docker images.
+# Use the --dry-run argument to prevent the actual build process from running.
+#
+# Note: This script should not be triggered manually. Only run it in CI.
+#
+# Required env variables:
+#
+# - `DOCKER_USER`
+# - `DOCKER_API_KEY`
+
+SUPPORTED_BRANCH_NAMES=("master")
+SUPPORTED_TAG_PATTERNS=("^v2.1.\([6789]\|1[0-9]\)$")
+IMAGE_NAME=threema/threema-web
+
+if [ $1 == "--dry-run" ]; then
+    echo -e "Dry run\n"
+    DOCKER='echo > docker'
+else
+    DOCKER="docker"
+fi
+
+echo "Logging in:"
+$DOCKER login -u $DOCKER_USER -p $DOCKER_API_KEY
+
+echo -e "\nBuilding branches:"
+for branch in $SUPPORTED_BRANCH_NAMES; do
+    echo -e "\n- $branch"
+    $DOCKER build . --no-cache -t $IMAGE_NAME:$branch
+done
+
+echo -e "\nBuilding tags:"
+for pattern in $SUPPORTED_TAG_PATTERNS; do
+    for tag in $(git tag | grep $pattern); do
+        echo -e "\n- $tag"
+        maintag=$tag
+        minortag=$(echo $tag | sed 's/^\(v[0-9]*\.[0-9]*\)\..*$/\1/')
+        majortag=$(echo $tag | sed 's/^\(v[0-9]*\)\..*$/\1/')
+        $DOCKER build . --no-cache -t $IMAGE_NAME:$tag -t $IMAGE_NAME:$minortag -t threema/threema
+    done
+done
+
+echo -e "\nPushing image with all tags"
+$DOCKER push $IMAGE_NAME