steps.go 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package actions
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. )
  6. func getCheckoutCodeStep() GithubActionYAMLStep {
  7. return GithubActionYAMLStep{
  8. Name: "Checkout code",
  9. Uses: "actions/checkout@v2.3.4",
  10. }
  11. }
  12. const download string = `
  13. name=$(curl -s https://api.github.com/repos/porter-dev/porter/releases/latest | grep "browser_download_url.*/porter_.*_Linux_x86_64\.zip" | cut -d ":" -f 2,3 | tr -d \")
  14. name=$(basename $name)
  15. curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
  16. unzip -a $name
  17. rm $name
  18. chmod +x ./porter
  19. sudo mv ./porter /usr/local/bin/porter
  20. `
  21. func getDownloadPorterStep() GithubActionYAMLStep {
  22. return GithubActionYAMLStep{
  23. Name: "Download Porter",
  24. ID: "download_porter",
  25. Run: download,
  26. }
  27. }
  28. const configure string = `
  29. sudo porter auth login --token ${{secrets.%s}}
  30. sudo porter docker configure
  31. `
  32. func getConfigurePorterStep(porterTokenSecretName string) GithubActionYAMLStep {
  33. return GithubActionYAMLStep{
  34. Name: "Configure Porter",
  35. ID: "configure_porter",
  36. Run: fmt.Sprintf(configure, porterTokenSecretName),
  37. }
  38. }
  39. const dockerBuildPush string = `
  40. export $(echo "${{secrets.%s}}" | xargs)
  41. sudo docker build %s --file %s -t %s:$(git rev-parse --short HEAD)
  42. sudo docker push %s:$(git rev-parse --short HEAD)
  43. `
  44. func getDockerBuildPushStep(envSecretName, dockerFilePath, repoURL string) GithubActionYAMLStep {
  45. return GithubActionYAMLStep{
  46. Name: "Docker build, push",
  47. ID: "docker_build_push",
  48. Run: fmt.Sprintf(dockerBuildPush, envSecretName, filepath.Dir(dockerFilePath), dockerFilePath, repoURL, repoURL),
  49. }
  50. }
  51. const buildPackPush string = `
  52. export $(echo "${{secrets.%s}}" | xargs)
  53. sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
  54. sudo apt-get update
  55. sudo apt-get install pack-cli
  56. sudo pack build %s:$(git rev-parse --short HEAD) --path %s --builder heroku/buildpacks:18
  57. sudo docker push %s:$(git rev-parse --short HEAD)
  58. `
  59. func getBuildPackPushStep(envSecretName, folderPath, repoURL string) GithubActionYAMLStep {
  60. return GithubActionYAMLStep{
  61. Name: "Docker build, push",
  62. ID: "docker_build_push",
  63. Run: fmt.Sprintf(buildPackPush, envSecretName, repoURL, folderPath, repoURL),
  64. }
  65. }
  66. const deployPorter string = `
  67. curl -X POST "https://dashboard.getporter.dev/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)&repository=%s"
  68. `
  69. func deployPorterWebhookStep(webhookTokenSecretName, repoURL string) GithubActionYAMLStep {
  70. return GithubActionYAMLStep{
  71. Name: "Deploy on Porter",
  72. ID: "deploy_porter",
  73. Run: fmt.Sprintf(deployPorter, webhookTokenSecretName, repoURL),
  74. }
  75. }