From a73daf6a1e0c927e91f3c2900ab79c7d8feb245c Mon Sep 17 00:00:00 2001 From: Guillaume Vincent Date: Thu, 7 May 2020 22:41:06 +0200 Subject: [PATCH] CICD for packages and containers --- .github/workflows/deploy-containers.yml | 29 ++++++++++++++++++++++ .github/workflows/deploy-packages.yml | 29 ++++++++++++++++++++++ .github/workflows/deploy.yml | 43 --------------------------------- .github/workflows/test.yml | 9 +++++++ bin/deploy_containers | 34 -------------------------- bin/deploy_node_modules | 30 ----------------------- containers/deploy | 33 +++++++++++++++++++++++++ packages/deploy | 30 +++++++++++++++++++++++ 8 files changed, 130 insertions(+), 107 deletions(-) create mode 100644 .github/workflows/deploy-containers.yml create mode 100644 .github/workflows/deploy-packages.yml delete mode 100644 .github/workflows/deploy.yml delete mode 100755 bin/deploy_containers delete mode 100755 bin/deploy_node_modules create mode 100755 containers/deploy create mode 100755 packages/deploy diff --git a/.github/workflows/deploy-containers.yml b/.github/workflows/deploy-containers.yml new file mode 100644 index 0000000..d2ffd11 --- /dev/null +++ b/.github/workflows/deploy-containers.yml @@ -0,0 +1,29 @@ +name: deploy-containers + +on: + push: + paths: + - 'containers/**' + +jobs: + test-containers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: test containers + run: | + cd container + ./test + + deploy-containers: + runs-on: ubuntu-latest + needs: test-containers + steps: + - uses: actions/checkout@v2 + - name: deploy containers + run: | + cd containers + ./deploy + env: + QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} + QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} diff --git a/.github/workflows/deploy-packages.yml b/.github/workflows/deploy-packages.yml new file mode 100644 index 0000000..15ee70c --- /dev/null +++ b/.github/workflows/deploy-packages.yml @@ -0,0 +1,29 @@ +name: deploy-packages + +on: + push: + paths: + - 'packages/**' + +jobs: + test-packages: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: test packages + run: | + yarn install + yarn test + + deploy-packages: + runs-on: ubuntu-latest + needs: test-packages + steps: + - uses: actions/checkout@v2 + - name: deploy packages + run: | + cd packages + ./deploy + continue-on-error: true + env: + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 067ad29..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: deploy - -on: - push: - tags: - - '*' - -jobs: - deploy-containers: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: deploy containers - run: | - ./bin/deploy_containers - env: - QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} - QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} - - deploy-node-modules: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: deploy node modules - run: | - ./bin/deploy_node_modules - env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} - - deploy-web-extensions: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: deploy web extensions - run: | - ./bin/deploy_web_extensions - env: - EXTENSION_ID: ${{ secrets.EXTENSION_ID }} - CLIENT_ID: ${{ secrets.CLIENT_ID }} - CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }} - REFRESH_TOKEN: ${{ secrets.REFRESH_TOKEN }} - WEB_EXT_API_KEY: ${{ secrets.WEB_EXT_API_KEY }} - WEB_EXT_API_SECRET: ${{ secrets.WEB_EXT_API_SECRET }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 025fb86..27e3085 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -51,3 +51,12 @@ jobs: python -m pip install --upgrade pip python -m pip install -r requirements.txt python manage.py test + + test-containers: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: test containers + run: | + cd container + ./test \ No newline at end of file diff --git a/bin/deploy_containers b/bin/deploy_containers deleted file mode 100755 index 1439a7f..0000000 --- a/bin/deploy_containers +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/env bash - -function check_env_variables_are_setted { - if [ -z "${QUAY_USERNAME}" ] || [ -z "${QUAY_PASSWORD}" ]; then - echo "Need to set QUAY_USERNAME and QUAY_PASSWORD env variables to release containers" - exit 1 - fi -} - -set +o errexit - -check_env_variables_are_setted - -set -o errexit -set -o pipefail -set -o nounset - -function build_and_push_container { - pushd containers - container=$1 - docker build --tag lesspass/${container} ./${container} - docker tag lesspass/${container} quay.io/lesspass/${container} - docker push quay.io/lesspass/${container} - popd -} - -function build_and_push_containers { - docker login --username="${QUAY_USERNAME}" --password="${QUAY_PASSWORD}" quay.io - build_and_push_container webserver - build_and_push_container backend - build_and_push_container frontend -} - -build_and_push_containers \ No newline at end of file diff --git a/bin/deploy_node_modules b/bin/deploy_node_modules deleted file mode 100755 index 8497e29..0000000 --- a/bin/deploy_node_modules +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -function check_env_variables_are_setted { - if [ -z "${NPM_TOKEN}" ]; then - echo "Need to set NPM_TOKEN env variable to release node modules" - exit 1 - fi -} - -set +o errexit - -check_env_variables_are_setted - -set -o errexit -set -o pipefail -set -o nounset - -function push_packages_on_npm { - touch ~/.npmrc - grep --fixed-strings --line-regexp --silent "//registry.npmjs.org/:_authToken=$NPM_TOKEN" ~/.npmrc || echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc - projects="lesspass lesspass-crypto lesspass-entropy lesspass-fingerprint lesspass-pure lesspass-render-password" - for project in ${projects} - do - pushd packages/${project} - yarn publish --non-interactive - popd - done -} - -push_packages_on_npm \ No newline at end of file diff --git a/containers/deploy b/containers/deploy new file mode 100755 index 0000000..af372d0 --- /dev/null +++ b/containers/deploy @@ -0,0 +1,33 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${QUAY_USERNAME}" ] || [ -z "${QUAY_PASSWORD}" ]; then + echo "Need to set QUAY_USERNAME and QUAY_PASSWORD env variables to release containers" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function build_and_push_container { + container=$1 + docker build --tag lesspass/${container} ./${container} + docker tag lesspass/${container} quay.io/lesspass/${container} + docker push quay.io/lesspass/${container} +} + +function build_and_push_containers { + docker login --username="${QUAY_USERNAME}" --password="${QUAY_PASSWORD}" quay.io + build_and_push_container webserver + build_and_push_container backend + build_and_push_container frontend + build_and_push_container blog +} + +build_and_push_containers \ No newline at end of file diff --git a/packages/deploy b/packages/deploy new file mode 100755 index 0000000..d7c29f9 --- /dev/null +++ b/packages/deploy @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +function check_env_variables_are_setted { + if [ -z "${NPM_TOKEN}" ]; then + echo "Need to set NPM_TOKEN env variable to release node modules" + exit 1 + fi +} + +set +o errexit + +check_env_variables_are_setted + +set -o errexit +set -o pipefail +set -o nounset + +function push_packages_on_npm { + touch ~/.npmrc + grep --fixed-strings --line-regexp --silent "//registry.npmjs.org/:_authToken=$NPM_TOKEN" ~/.npmrc || echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc + projects="lesspass lesspass-crypto lesspass-entropy lesspass-fingerprint lesspass-pure lesspass-render-password" + for project in ${projects} + do + pushd ${project} + yarn publish --non-interactive + popd + done +} + +push_packages_on_npm \ No newline at end of file