|
@@ -2,7 +2,6 @@ package actions
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
- "path/filepath"
|
|
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func getCheckoutCodeStep() GithubActionYAMLStep {
|
|
func getCheckoutCodeStep() GithubActionYAMLStep {
|
|
@@ -12,8 +11,7 @@ func getCheckoutCodeStep() GithubActionYAMLStep {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const download string = `
|
|
|
|
|
-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 \")
|
|
|
|
|
|
|
+const download string = `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 \")
|
|
|
name=$(basename $name)
|
|
name=$(basename $name)
|
|
|
curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
|
|
curl -L https://github.com/porter-dev/porter/releases/latest/download/$name --output $name
|
|
|
unzip -a $name
|
|
unzip -a $name
|
|
@@ -30,61 +28,19 @@ func getDownloadPorterStep() GithubActionYAMLStep {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const configure string = `
|
|
|
|
|
-sudo porter config set-host %s
|
|
|
|
|
-sudo porter auth login --token ${{secrets.%s}}
|
|
|
|
|
-sudo porter docker configure
|
|
|
|
|
-`
|
|
|
|
|
-
|
|
|
|
|
-func getConfigurePorterStep(serverURL, porterTokenSecretName string) GithubActionYAMLStep {
|
|
|
|
|
- return GithubActionYAMLStep{
|
|
|
|
|
- Name: "Configure Porter",
|
|
|
|
|
- ID: "configure_porter",
|
|
|
|
|
- Run: fmt.Sprintf(configure, serverURL, porterTokenSecretName),
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const dockerBuildPush string = `
|
|
|
|
|
-export $(echo "${{secrets.%s}}" | xargs)
|
|
|
|
|
-echo "${{secrets.%s}}" > ./env_porter
|
|
|
|
|
-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)
|
|
|
|
|
-sudo docker push %s:$(git rev-parse --short HEAD)
|
|
|
|
|
-`
|
|
|
|
|
-
|
|
|
|
|
-func getDockerBuildPushStep(envSecretName, dockerFilePath, repoURL string) GithubActionYAMLStep {
|
|
|
|
|
- return GithubActionYAMLStep{
|
|
|
|
|
- Name: "Docker build, push",
|
|
|
|
|
- ID: "docker_build_push",
|
|
|
|
|
- Run: fmt.Sprintf(dockerBuildPush, envSecretName, envSecretName, filepath.Dir(dockerFilePath), dockerFilePath, repoURL, repoURL),
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const buildPackPush string = `
|
|
|
|
|
-export $(echo "${{secrets.%s}}" | xargs)
|
|
|
|
|
-echo "${{secrets.%s}}" > ./env_porter
|
|
|
|
|
-sudo add-apt-repository ppa:cncf-buildpacks/pack-cli
|
|
|
|
|
-sudo apt-get update
|
|
|
|
|
-sudo apt-get install pack-cli
|
|
|
|
|
-sudo pack build %s:$(git rev-parse --short HEAD) --path %s --builder heroku/buildpacks:18 --env-file ./env_porter
|
|
|
|
|
-sudo docker push %s:$(git rev-parse --short HEAD)
|
|
|
|
|
-`
|
|
|
|
|
-
|
|
|
|
|
-func getBuildPackPushStep(envSecretName, folderPath, repoURL string) GithubActionYAMLStep {
|
|
|
|
|
- return GithubActionYAMLStep{
|
|
|
|
|
- Name: "Docker build, push",
|
|
|
|
|
- ID: "docker_build_push",
|
|
|
|
|
- Run: fmt.Sprintf(buildPackPush, envSecretName, envSecretName, repoURL, folderPath, repoURL),
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const deployPorter string = `
|
|
|
|
|
-curl -X POST "%s/api/webhooks/deploy/${{secrets.%s}}?commit=$(git rev-parse --short HEAD)"
|
|
|
|
|
-`
|
|
|
|
|
|
|
+const configure string = `porter update --app %s`
|
|
|
|
|
|
|
|
-func deployPorterWebhookStep(serverURL, webhookTokenSecretName string) GithubActionYAMLStep {
|
|
|
|
|
|
|
+func getConfigurePorterStep(serverURL, porterTokenSecretName string, projectID uint, clusterID uint, appName string) GithubActionYAMLStep {
|
|
|
return GithubActionYAMLStep{
|
|
return GithubActionYAMLStep{
|
|
|
- Name: "Deploy on Porter",
|
|
|
|
|
- ID: "deploy_porter",
|
|
|
|
|
- Run: fmt.Sprintf(deployPorter, serverURL, webhookTokenSecretName),
|
|
|
|
|
|
|
+ Name: "Update Porter App",
|
|
|
|
|
+ ID: "update_porter",
|
|
|
|
|
+ Run: fmt.Sprintf(configure, appName),
|
|
|
|
|
+ Timeout: 20,
|
|
|
|
|
+ Env: map[string]string{
|
|
|
|
|
+ "PORTER_TOKEN": fmt.Sprintf("${{ secrets.%s }}", porterTokenSecretName),
|
|
|
|
|
+ "PORTER_HOST": serverURL,
|
|
|
|
|
+ "PORTER_PROJECT": fmt.Sprintf("%d", projectID),
|
|
|
|
|
+ "PORTER_CLUSTER": fmt.Sprintf("%d", clusterID),
|
|
|
|
|
+ },
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|