Skip to content

Instantly share code, notes, and snippets.

@userbradley
Created December 6, 2021 10:59
Show Gist options
  • Save userbradley/d1da06af25ec36cd51c5750e9697b95e to your computer and use it in GitHub Desktop.
Save userbradley/d1da06af25ec36cd51c5750e9697b95e to your computer and use it in GitHub Desktop.
Codefresh Pipeline
version: "1.0"
stages:
- "setup"
- "mkdocs-build"
- "docker-build"
- "deploy"
steps:
clone:
title: "Cloning repository"
type: "git-clone"
repo: "bysd-project/bysd-portfolio"
revision: "${{CF_BRANCH}}"
git: "github"
stage: "setup"
set-env:
title: "Set env vars"
stage: "setup"
working_directory: /codefresh/volume
image: alpine
commands:
- echo "${{google_key}}" | base64 -d > .key
- export GOOGLE_APPLICATION_CREDENTIALS="/codefresh/volume/.key"
- export GOOGLE_PROJECT="bysd-project"
- export CLOUDSDK_CORE_PROJECT="bysd-project"
- export GOOGLE_ZONE="europe-west2-c"
- export TF_VAR_location="europe-west2"
- export TF_VAR_tag="${{CF_SHORT_REVISION}}"
- export TF_VAR_project="bysd-project"
- cf_export GOOGLE_APPLICATION_CREDENTIALS GOOGLE_PROJECT CLOUDSDK_CORE_PROJECT GOOGLE_ZONE TF_VAR_location TF_VAR_tag TF_VAR_project
build_mkdocs:
title: Build Mkdocs site
stage: "mkdocs-build"
image: "squidfunk/mkdocs-material"
working_directory: "./bysd-portfolio/content/"
volumes:
- ./:/docs
- bysd-portfolio/content/site:/output
cmd:
- "build"
make_dir_and_copy_files:
title: "Make directory and copy files"
image: alpine
stage: "docker-build"
commands:
- "mkdir -p /codefresh/volume/bysd-portfolio/docker/site"
- "cp -r /codefresh/volume/bysd-portfolio/content/site/* /codefresh/volume/bysd-portfolio/docker/site/"
build_docker:
title: "Building Docker image"
type: "build"
image_name: "${{gcp_project}}/bysd-portfolio"
working_directory: "bysd-portfolio/docker"
tag: "${{CF_SHORT_REVISION}}"
dockerfile: "Dockerfile"
stage: "docker-build"
DeployingSiteToLocations:
type: parallel
stage: 'push'
steps:
DeployWithTerraform:
image: hashicorp/terraform:light
title: Deploying Terraform plan
stage: 'deploy'
working_directory: "/codefresh/volume/bysd-portfolio/infra/"
commands:
- terraform init
- terraform apply --auto-approve -lock=false #Forced to to this as it's locked somewhere sometimes
transfer:
title: "SCP to web server"
type: "freestyle"
stage: "deploy"
image: "ictu/sshpass:latest"
commands:
- "mkdir /.ssh"
- "echo ${{codefresh_ssh_key}} | base64 -d > /.ssh/id_rsa"
- "chmod 600 /.ssh/id_rsa"
- ssh -o "StrictHostKeyChecking no" -i /.ssh/id_rsa root@reverse.breadinfra.net 'whoami'
- scp -o "StrictHostKeyChecking no" -i /.ssh/id_rsa -r /codefresh/volume/bysd-portfolio/content/site/* root@reverse.breadinfra.net:/var/www/cv.breadnet.co.uk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment