diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 5c77a9a90..000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,93 +0,0 @@ -version: 2 -jobs: - - testjs: - docker: - - image: circleci/node:lts - steps: - - checkout - - restore_cache: - keys: - - v1-npm-deps-{{ .Branch }}-{{ checksum "package-lock.json" }} - - v1-npm-deps-{{ .Branch }} - - v1-npm-deps- - - run: - name: npm install - command: npm install - - - save_cache: - key: v1-npm-deps-{{ .Branch }}-{{ checksum "package-lock.json" }} - paths: - - ~/usr/local/lib/node_modules - - ./node_modules - - - run: - name: Run js tests - command: npm run test -- --coverage --collectCoverage=true - - - store_artifacts: - path: coverage - - build: - docker: - - image: tmaier/docker-compose - - steps: - - checkout - - setup_remote_docker - - restore_cache: - keys: - - v1-{{ .Branch }} - paths: - - /caches/app.tar - - - run: - name: Load Docker image layer cache - command: | - set +o pipefail - docker load -i /caches/app.tar | true - - - run: - name: Build application Docker image - command: | - docker build --cache-from=controlpanel -t controlpanel . - - - run: - name: Save Docker image layer cache - command: | - mkdir -p /caches - docker save -o /caches/app.tar controlpanel - - - save_cache: - key: v1-{{ .Branch }}-{{ epoch }} - paths: - - /caches/app.tar - - - run: - name: Run python tests - command: | - touch .env # empty .env file to avoid error - docker-compose run \ - -e DJANGO_SETTINGS_MODULE=controlpanel.settings.test \ - -e KUBECONFIG=tests/kubeconfig \ - cpanel \ - sh -c "until pg_isready -h db; do sleep 2; done; pytest" - - - deploy: - name: Push application Docker image - command: | - BRANCH=$(echo -n $CIRCLE_BRANCH | tr '/' '-') - docker login -u ${QUAY_USERNAME} -p ${QUAY_PASSWORD} quay.io - docker tag controlpanel "quay.io/mojanalytics/control-panel:${CIRCLE_SHA1}" - docker tag controlpanel "quay.io/mojanalytics/control-panel:${BRANCH}" - docker push "quay.io/mojanalytics/control-panel:${CIRCLE_SHA1}" - docker push "quay.io/mojanalytics/control-panel:${BRANCH}" - -workflows: - version: 2 - build_and_test: - jobs: - - testjs - - build: - requires: - - testjs diff --git a/.github/workflows/test-and-push-docker-image.yaml b/.github/workflows/test-and-push-docker-image.yaml new file mode 100644 index 000000000..8c706aed4 --- /dev/null +++ b/.github/workflows/test-and-push-docker-image.yaml @@ -0,0 +1,107 @@ +name: Run tests and push Docker image on success + +on: + push: + branches: + - main + pull_request: + +jobs: + + test-js: + runs-on: ubuntu-latest + strategy: + matrix: + node-version: [8.x, 10.x, 12.x] + + steps: + - uses: actions/checkout@v2 + + - name: Set up Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + + - name: Install JavaScript dependencies + run: npm install + + - name: Run JavaScript tests + run: npm run test -- --coverage --collectCoverage=true + + test-and-push-docker-image-to-quay: + runs-on: ubuntu-latest + needs: [test-js] + + steps: + - uses: actions/checkout@v2 + + # Docker build + + - name: Docker Layer Caching + uses: satackey/action-docker-layer-caching@v0.0.8 + continue-on-error: true + + - name: Build docker image + run: docker build --cache-from=controlpanel -t controlpanel . + + # Run Python tests using docker-compose + + - name: Run Python tests (docker-compose) + run: | + touch .env # empty .env file to avoid error + docker-compose run \ + -e DJANGO_SETTINGS_MODULE=controlpanel.settings.test \ + -e KUBECONFIG=tests/kubeconfig \ + cpanel \ + sh -c "until pg_isready -h db; do sleep 2; done; pytest" + + # Get info to tag Docker image + # + # This is a bit more complicated than expected, see: + # - get branch name: https://stackoverflow.com/a/64210623/455642 + # - get commit SHA1: https://github.community/t/github-sha-isnt-the-value-expected/17903 + - name: Get branch name and commit SHA1 + run: | + BRANCH_NAME="" + COMMIT_SHA1="" + + if [[ "${{ github.event_name }}" == "pull_request" ]]; then + BRANCH_NAME="${GITHUB_HEAD_REF}" + COMMIT_SHA1="${{ github.event.pull_request.head.sha }}" + else + BRANCH_NAME="${GITHUB_REF#refs/heads/}" + COMMIT_SHA1="${GITHUB_SHA}" + fi + + # Replace slashes ("/") with dashes ("-") + BRANCH_NAME=$(echo "${BRANCH_NAME}" | tr / -) + + # Print environment variables to output + echo "BRANCH_NAME=${BRANCH_NAME}" + echo "COMMIT_SHA1=${COMMIT_SHA1}" + + # Save environment variables for future steps + echo "BRANCH_NAME=${BRANCH_NAME}" >> $GITHUB_ENV + echo "COMMIT_SHA1=${COMMIT_SHA1}" >> $GITHUB_ENV + + # Tag and push Docker image to Quay.io + + - name: Push Docker image to Quay.io + env: + QUAY_USERNAME: ${{ secrets.QUAY_USERNAME }} + QUAY_PASSWORD: ${{ secrets.QUAY_PASSWORD }} + run: | + docker login -u ${QUAY_USERNAME} -p ${QUAY_PASSWORD} quay.io + echo + + echo "tagging quay.io/mojanalytics/control-panel:${COMMIT_SHA1}..." + docker tag controlpanel "quay.io/mojanalytics/control-panel:${COMMIT_SHA1}" + echo "tagging quay.io/mojanalytics/control-panel:${BRANCH_NAME}..." + docker tag controlpanel "quay.io/mojanalytics/control-panel:${BRANCH_NAME}" + echo + + echo "pushing quay.io/mojanalytics/control-panel:${COMMIT_SHA1}..." + docker push "quay.io/mojanalytics/control-panel:${COMMIT_SHA1}" + echo + echo "pushing quay.io/mojanalytics/control-panel:${BRANCH_NAME}..." + docker push "quay.io/mojanalytics/control-panel:${BRANCH_NAME}"