Skip to content

Instantly share code, notes, and snippets.

@joseabraham
Created February 21, 2023 18:59
Show Gist options
  • Save joseabraham/ba7fa632085c5730caaaa9bfb0cd94fa to your computer and use it in GitHub Desktop.
Save joseabraham/ba7fa632085c5730caaaa9bfb0cd94fa to your computer and use it in GitHub Desktop.
Bitbucket Linode Kubernetes Pipeline
# This is a sample build configuration for Python.
# Check our guides at https://confluence.atlassian.com/x/x4UWN for more examples.
# Only use spaces to indent your .yml configuration.
# -----
# You can specify a custom docker image from Docker Hub as your build environment.
definitions:
services:
docker:
memory: 4096
pipelines:
branches:
master:
# - step:
# name: Test
# script:
# - npm install
# - npm test
- step:
name: Build
size: 2x
script:
- export IMAGE_NAME=$DOCKERHUB_USERNAME/$APPLICATION_NAME:$BITBUCKET_COMMIT
# build the Docker image (this will use the Dockerfile in the root of the repo)
- docker build -t $IMAGE_NAME .
# authenticate with the Docker Hub registry
- docker login --username $DOCKERHUB_USERNAME --password $DOCKERHUB_TOKEN
# push the new Docker image to the Docker registry
- docker push $IMAGE_NAME
- export DOCKER_CONFIG=$(cat ~/.docker/config.json | base64 -w 0)
- echo "$DOCKER_CONFIG" > config.txt
- echo "$IMAGE_NAME" > image_name.txt
services:
- docker
artifacts:
- config.txt
- image_name.txt
- step:
name: Deploy
size: 2x
deployment: production
script:
- DOCKER_CONFIG=$(cat ./config.txt)
- IMAGE_NAME=$(cat ./image_name.txt)
- |
sed -i -e "s|DOCKER_HUB_USERNAME|$DOCKER_HUB_USERNAME|g" \
-e "s|IMAGE_NAME|$IMAGE_NAME|g" \
-e "s|APPLICATION_NAME|$APPLICATION_NAME|g" \
-e "s|BITBUCKET_COMMIT|$BITBUCKET_COMMIT|g" \
-e "s|JWT_TOKEN_SECRET_VAL|$JWT_TOKEN_SECRET|g" \
-e "s|JWT_TOKEN_SECRET_API_VAL|$JWT_TOKEN_SECRET_API|g" \
-e "s|MONGO_URL_VAL|$MONGO_URL|g" \
-e "s|MONGO_URL_DEFI_VAL|$MONGO_URL_DEFI|g" \
-e "s|DOCKER_CONFIG|$DOCKER_CONFIG|g" k8s.yaml
- echo $KUBE_CONFIG | base64 -d > kubeconfig.yml
- pipe: atlassian/kubectl-run:3.4.0
variables:
KUBE_CONFIG: $KUBE_CONFIG
KUBECTL_COMMAND: "apply"
RESOURCE_PATH: 'k8s.yaml'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment