Skip to content

Commit

Permalink
[#860] Initial test on Github Action
Browse files Browse the repository at this point in the history
  • Loading branch information
anjarakvo committed Jan 8, 2024
1 parent 9e767d5 commit de5919f
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 88 deletions.
14 changes: 14 additions & 0 deletions .github/actions/install-google-cloud-sdk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: 'Install GKE Auth Plugin Action'
description: 'Install GKE Auth Plugin Action'
runs:
using: "composite"
steps:
- run: |
REPO_URL="https://packages.cloud.google.com/apt"
# Install the Google Cloud SDK
echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] $REPO_URL cloud-sdk main" | sudo tee /etc/apt/sources.list.d/google-cloud-sdk.list
sudo curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
sudo apt-get update -y
sudo apt-get install -y google-cloud-sdk-gke-gcloud-auth-plugin
shell: bash
123 changes: 123 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: RTMIS CI

on:
push:
branch:
"*"
pull_request:
types: [synchronize]

jobs:
build_pull_request_action:
if: github.event_name == 'pull_request' && github.event.action == 'synchronize'
name: RTMIS pipeline for pull request
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install GKE auth plugin
uses: ./.github/actions/install-google-cloud-sdk

- name: Set short git commit SHA
id: vars
run: |
shortSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$shortSha" >> $GITHUB_ENV
- name: Create credentials folder
run: mkdir /home/runner/work/test-rtmis/credentials
shell: bash

- name: Write gcp deployment secret to file
run: echo "${{ secrets.GCLOUD_SERVICE_ACCOUNT }}" | base64 --decode > /home/runner/work/test-rtmis/credentials/gcp.json
shell: bash

- name: Write gcp deployment secret to file
run: echo "${{ secrets.RTMIS_SERVICE_ACCOUNT }}" | base64 --decode > /home/runner/work/test-rtmis/credentials/rtmis-service-account.json
shell: bash

- name: Build and test
env:
CI_COMMIT: ${{ env.COMMIT_SHORT_SHA }}
CI_BRANCH: ${{ github.ref_name }}
CI_TAG: ${{ github.ref_name }}
CI_PULL_REQUEST: true
CI_COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
COMPOSE_INTERACTIVE_NO_CLI: 1
COVERALLS_REPO_TOKEN: "${COVERALLS_RTMIS_TOKEN}"
SERVICE_ACCOUNT: "/home/runner/work/test-rtmis/credentials"
run: |
./ci/build.sh
- name: Deploy
env:
CI_COMMIT: ${{ env.COMMIT_SHORT_SHA }}
CI_BRANCH: ${{ github.ref_name }}
CI_TAG: ${{ github.ref_name }}
CI_PULL_REQUEST: true
CI_COMMIT_RANGE: ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
COMPOSE_INTERACTIVE_NO_CLI: 1
COVERALLS_REPO_TOKEN: "${COVERALLS_RTMIS_TOKEN}"
SERVICE_ACCOUNT: "/home/runner/work/test-rtmis/credentials"
run: |
./ci/deploy.sh
build_push_action:
if: github.event_name == 'push'
name: RTMIS pipeline for push action
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Install GKE auth plugin
uses: ./.github/actions/install-google-cloud-sdk

- name: Set short git commit SHA
id: vars
run: |
shortSha=$(git rev-parse --short ${{ github.sha }})
echo "COMMIT_SHORT_SHA=$shortSha" >> $GITHUB_ENV
- name: Create credentials folder
run: mkdir /home/runner/work/test-rtmis/credentials
shell: bash

- name: Write gcp deployment secret to file
run: echo "${{ secrets.GCLOUD_SERVICE_ACCOUNT }}" | base64 --decode > /home/runner/work/test-rtmis/credentials/gcp.json
shell: bash

- name: Write gcp deployment secret to file
run: echo "${{ secrets.RTMIS_SERVICE_ACCOUNT }}" | base64 --decode > /home/runner/work/test-rtmis/credentials/rtmis-service-account.json
shell: bash

- name: Build and test
env:
CI_COMMIT: ${{ env.COMMIT_SHORT_SHA }}
CI_BRANCH: ${{ github.ref_name }}
CI_TAG: ""
CI_PULL_REQUEST: false
CI_COMMIT_RANGE: ${{ github.event.before }}..${{ github.sha }}
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
COMPOSE_INTERACTIVE_NO_CLI: 1
COVERALLS_REPO_TOKEN: "${secrets.COVERALLS_RTMIS_TOKEN}"
SERVICE_ACCOUNT: "/home/runner/work/test-rtmis/credentials"
run: |
./ci/build.sh
- name: Deploy
env:
CI_COMMIT: ${{ env.COMMIT_SHORT_SHA }}
CI_BRANCH: ${{ github.ref_name }}
CI_TAG: ""
CI_PULL_REQUEST: false
CI_COMMIT_RANGE: ${{ github.event.before }}..${{ github.sha }}
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
COMPOSE_INTERACTIVE_NO_CLI: 1
COVERALLS_REPO_TOKEN: "${COVERALLS_RTMIS_TOKEN}"
SERVICE_ACCOUNT: "/home/runner/work/test-rtmis/credentials"
run: |
./ci/deploy.sh
63 changes: 0 additions & 63 deletions .semaphore/semaphore.yml

This file was deleted.

24 changes: 1 addition & 23 deletions ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,6 @@ set -exuo pipefail
[[ "${CI_BRANCH}" == "gh-pages" ]] && { echo "GH Pages update. Skip all"; exit 0; }
[[ -n "${CI_TAG:=}" ]] && { echo "Skip build"; exit 0; }

## RESTORE IMAGE CACHE
IMAGE_CACHE_LIST=$(grep image ./docker-compose.yml \
| sort -u | sed 's/image\://g' \
| sed 's/^ *//g')
mkdir -p ./ci/images

while IFS= read -r IMAGE_CACHE; do
IMAGE_CACHE_LOC="./ci/images/${IMAGE_CACHE//\//-}.tar"
if [ -f "${IMAGE_CACHE_LOC}" ]; then
docker load -i "${IMAGE_CACHE_LOC}"
fi
done <<< "${IMAGE_CACHE_LIST}"

if grep -q .yml .gitignore; then
echo "ERROR: .gitignore contains other docker-compose file"
exit 1
Expand Down Expand Up @@ -146,13 +133,4 @@ if [[ ${FRONTEND_CHANGES} == 1 && ${BACKEND_CHANGES} == 1 ]]; then
echo "Build failed when running basic.sh"
exit 1
fi
fi

## STORE IMAGE CACHE
while IFS= read -r IMAGE_CACHE; do
IMAGE_CACHE_LOC="./ci/images/${IMAGE_CACHE//\//-}.tar"
if [[ ! -f "${IMAGE_CACHE_LOC}" ]]; then
docker save -o "${IMAGE_CACHE_LOC}" "${IMAGE_CACHE}"
fi
done <<< "${IMAGE_CACHE_LIST}"
## END STORE IMAGE CACHE
fi
3 changes: 1 addition & 2 deletions ci/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -exuo pipefail
[[ "${CI_PULL_REQUEST}" == "true" ]] && { echo "Pull request. Skip deploy"; exit 0; }

auth () {
gcloud auth activate-service-account --key-file=/home/semaphore/.secrets/gcp.json
gcloud auth activate-service-account --key-file=/home/runner/work/test-rtmis/credentials/gcp.json
gcloud config set project akvo-lumen
gcloud config set container/cluster europe-west1-d
gcloud config set compute/zone europe-west1-d
Expand Down Expand Up @@ -49,4 +49,3 @@ prepare_deployment
apply_deployment

ci/k8s/wait-for-k8s-deployment-to-be-ready.sh

0 comments on commit de5919f

Please sign in to comment.