Merge pull request #12 from senacor/feature/add_monitoring #79
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy to dev environment | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- main | |
env: | |
IMAGE_APPLICATION_BUILD_NAME: lpt-application | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Setup JDK 19 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '21' | |
- name: Setup Gradle | |
uses: gradle/actions/setup-gradle@v3 | |
- name: Google auth | |
uses: 'google-github-actions/auth@v2' | |
with: | |
credentials_json: ${{ secrets.AUTOMATION_SA_KEY_JSON }} | |
- uses: azure/setup-kubectl@v4 | |
- name: Get GKE creds | |
id: get_gke_creds | |
uses: 'google-github-actions/get-gke-credentials@v2' | |
with: | |
cluster_name: 'simple-autopilot-private-cluster' | |
location: 'europe-west1' | |
credentials: ${{ secrets.AUTOMATION_SA_KEY_JSON }} | |
- uses: webfactory/[email protected] | |
with: | |
ssh-private-key: | | |
${{ secrets.LPT_SSH_PRIVATE_KEY }} | |
- name: Build service artifact | |
run: ./gradlew build | |
- name: Build Docker image | |
run: docker build . -t $IMAGE_APPLICATION_BUILD_NAME | |
- name: Docker login | |
uses: docker/login-action@v3 | |
with: | |
registry: europe-west1-docker.pkg.dev | |
username: _json_key | |
password: ${{ secrets.AUTOMATION_SA_KEY_JSON }} | |
- name: Build docker image name | |
run: | | |
PROJECT_NAME=$( ./gradlew properties | grep ^name: | awk '{print $2}' ) | |
VERSION_TAG=${{ github.run_number }} | |
IMAGE_NAME_GCP_REGISTRY=$DOCKER_IMAGE_PREFIX/$PROJECT_NAME:$VERSION_TAG | |
echo $IMAGE_NAME_GCP_REGISTRY | |
echo "IMAGE_NAME_GCP_REGISTRY=$IMAGE_NAME_GCP_REGISTRY" >> $GITHUB_ENV | |
echo "VERSION_TAG=$VERSION_TAG" >> $GITHUB_ENV | |
env: | |
DOCKER_IMAGE_PREFIX: ${{ vars.DOCKER_IMAGE_PATH_PREFIX }} | |
- name: Push image to GAR | |
run: | | |
docker tag $IMAGE_APPLICATION_BUILD_NAME $IMAGE_NAME_GCP_REGISTRY | |
docker push $IMAGE_NAME_GCP_REGISTRY | |
- name: Apply deployment | |
env: | |
BASTION_IP: ${{ secrets.SSH_BASTION_HOST_IP }} | |
API_URL: ${{ vars.KUBE_INTERNAL_API_URL }} | |
CLUSTER_NAME: ${{ vars.KUBE_CLUSTER_NAME }} | |
KUBE_FLAGS: ${{ vars.KUBE_FLAGS }} | |
CONFIG_PATH: ${{ steps.get_gke_creds.outputs.kubeconfig_path }} | |
run: | | |
ssh -o ExitOnForwardFailure=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -L 6443:$API_URL -i lpt lpt@$BASTION_IP -fN | |
# use config from gke init action: | |
export KUBECONFIG=$CONFIG_PATH | |
kubectl config set-cluster $CLUSTER_NAME --server=https://127.0.0.1:6443 | |
# kubectl config view | |
kubectl version $KUBE_FLAGS | |
# Replace new image tag | |
export IMAGE_TAG_TO_DEPLOY="$VERSION_TAG" | |
cat src/k8s/kustomization.yaml | envsubst > src/k8s/kustomization.yaml.tmp && mv src/k8s/kustomization.yaml.tmp src/k8s/kustomization.yaml | |
kubectl apply -k src/k8s $KUBE_FLAGS |