video-iac/bitbucket-pipelines.yml

85 lines
3.8 KiB
YAML
Raw Normal View History

2021-07-16 15:15:34 +00:00
# Template docker-push
# This template allows you to build and push your docker image to a Docker Hub account.
# The workflow allows running tests, code linting and security scans on feature branches (as well as master).
# The docker image will be validated and pushed to the docker registry after the code is merged to master.
# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD setup as deployment variables
image: atlassian/default-image:2
definitions:
services:
docker:
memory: 3072
pipelines:
default:
- parallel:
- step:
name: Build and Test
script:
2021-08-10 17:36:34 +00:00
- docker build . --file k8s/Dockerfile-autoscaler --tag autoscaler-${BITBUCKET_REPO_SLUG}
- docker build . --file k8s/Dockerfile-coturn-dns --tag coturn-dns-${BITBUCKET_REPO_SLUG}
2021-07-16 15:15:34 +00:00
services:
- docker
caches:
- docker
- step:
name: Lint the Dockerfile
image: hadolint/hadolint:latest-debian
script:
2021-08-10 17:36:34 +00:00
- hadolint Dockerfile-autoscaler
- hadolint Docuerfile-coturn-dns
2021-07-16 15:15:34 +00:00
branches:
2021-07-16 15:24:04 +00:00
main:
2021-07-16 15:15:34 +00:00
- step:
name: Build and Test
script:
2021-08-10 17:36:34 +00:00
- docker build . --file k8s/Dockerfile-autoscaler --tag autoscaler-${BITBUCKET_REPO_SLUG}
- docker build . --file k8s/Dockerfile-coturn-dns --tag coturn-dns-${BITBUCKET_REPO_SLUG}
- docker save autoscaler-${BITBUCKET_REPO_SLUG} --output "autoscaler-${BITBUCKET_REPO_SLUG}.tar"
- docker save coturn-dns-${BITBUCKET_REPO_SLUG} --output "coturn-dns-${BITBUCKET_REPO_SLUG}.tar"
2021-07-16 15:15:34 +00:00
services:
- docker
caches:
- docker
artifacts:
- "*.tar"
- step:
2021-07-19 17:05:41 +00:00
name: Push docker images to GCR
2021-07-16 15:15:34 +00:00
image: google/cloud-sdk:alpine
script:
# Authenticating with the service account key file
- echo $GCLOUD_API_KEYFILE | base64 -d > ./gcloud-api-key.json
- gcloud auth activate-service-account --key-file gcloud-api-key.json
- gcloud config set project $GCLOUD_PROJECT
2021-08-10 17:36:34 +00:00
- docker load --input "autoscaler-${BITBUCKET_REPO_SLUG}.tar"
- docker load --input "coturn-dns-${BITBUCKET_REPO_SLUG}.tar"
2021-07-16 15:15:34 +00:00
- VERSION="prod-0.1.${BITBUCKET_BUILD_NUMBER}"
2021-08-10 17:50:19 +00:00
- docker tag "autoscaler-${BITBUCKET_REPO_SLUG}" "gcr.io/${GCLOUD_PROJECT}/autoscaler:${VERSION}"
- docker tag "coturn-dns-${BITBUCKET_REPO_SLUG}" "gcr.io/${GCLOUD_PROJECT}/coturn-dns:${VERSION}"
2021-07-16 15:15:34 +00:00
# Login to google docker hub
- cat ./gcloud-api-key.json | docker login -u _json_key --password-stdin https://gcr.io
2021-08-10 17:36:34 +00:00
- docker push "gcr.io/${GCLOUD_PROJECT}/autoscaler:${VERSION}"
- docker push "gcr.io/${GCLOUD_PROJECT}/coturn-dns:${VERSION}"
2021-07-16 15:15:34 +00:00
services:
- docker
- step:
name: Deploy to K8s
deployment: production
script:
2021-08-10 18:24:42 +00:00
- AUTOSCALER_IMAGE="gcr.io/$GCLOUD_PROJECT/autoscaler:prod-0.1.$BITBUCKET_BUILD_NUMBER"
- sed -i "s|{{linode_autoscaler_image}}|$AUTOSCALER_IMAGE|g" k8s/linode-autoscaler/webrtc-be-autoscaler.yaml
- sed -i "s|{{linode_autoscaler_image}}|$AUTOSCALER_IMAGE|g" k8s/linode-autoscaler/coturn-autoscaler.yaml
- sed -i "s|{{coturn_dns_image}}|$AUTOSCALER_IMAGE|g" k8s/coturn-dns/coturn-dns.yaml
2021-07-16 15:15:34 +00:00
- pipe: atlassian/kubectl-run:1.1.2
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
2021-07-30 19:43:56 +00:00
RESOURCE_PATH: 'k8s/linode-autoscaler/'
- pipe: atlassian/kubectl-run:1.1.2
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: 'apply'
RESOURCE_PATH: 'k8s/external-dns/'