steps.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. echo "${{secrets.%s}}" > ./env_porter
  42. sudo docker build %s $(cat ./env_porter | awk 'NF' | sed 's@^@--build-arg @g' | paste -s -d " " -) --file %s -t %s:$(git rev-parse --short HEAD)
  43. sudo docker push %s:$(git rev-parse --short HEAD)
  44. `
  45. func getDockerBuildPushStep(envSecretName, dockerFilePath, repoURL string) GithubActionYAMLStep {
  46. return GithubActionYAMLStep{
  47. Name: "Docker build, push",
  48. ID: "docker_build_push",
  49. Run: fmt.Sprintf(dockerBuildPush, envSecretName, envSecretName, filepath.Dir(dockerFilePath), dockerFilePath, repoURL, repoURL),
  50. }
  51. }
  52. const buildPackPush string = `
  53. export $(echo "${{secrets.%s}}" | xargs)
  54. echo "${{secrets.%s}}" > ./env_porter
  55. sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
  56. sudo apt-get update
  57. sudo apt-get install pack-cli
  58. sudo pack build %s:$(git rev-parse --short HEAD) --path %s --builder heroku/buildpacks:18 --env-file ./env_porter
  59. sudo docker push %s:$(git rev-parse --short HEAD)
  60. `
  61. func getBuildPackPushStep(envSecretName, folderPath, repoURL string) GithubActionYAMLStep {
  62. return GithubActionYAMLStep{
  63. Name: "Docker build, push",
  64. ID: "docker_build_push",
  65. Run: fmt.Sprintf(buildPackPush, envSecretName, envSecretName, repoURL, folderPath, repoURL),
  66. }
  67. }
  68. const deployPorter string = `
  69. curl -X POST "https://dashboard.getporter.dev/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)&repository=%s"
  70. `
  71. func deployPorterWebhookStep(webhookTokenSecretName, repoURL string) GithubActionYAMLStep {
  72. return GithubActionYAMLStep{
  73. Name: "Deploy on Porter",
  74. ID: "deploy_porter",
  75. Run: fmt.Sprintf(deployPorter, webhookTokenSecretName, repoURL),
  76. }
  77. }