Skip to content

Commit

Permalink
Merge branch 'main' into remove-dockerhub-creds
Browse files Browse the repository at this point in the history
  • Loading branch information
CuriousLearner authored Oct 25, 2024
2 parents 76e2e35 + 2b2da0d commit caa5c8a
Show file tree
Hide file tree
Showing 18 changed files with 216 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: databases
on:
workflow_dispatch: {}
schedule:
- cron: '0 1 * * *'
- cron: '0 2 * * *'

jobs:
init:
Expand Down
58 changes: 57 additions & 1 deletion .github/workflows/functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: functional-tests
on:
workflow_dispatch: {}
schedule:
- cron: '0 1 * * *'
- cron: '0 0 * * *'

jobs:
functional-tests:
Expand All @@ -23,6 +23,7 @@ jobs:
-
name: Build
run: go build

-
name: AppPack Account
run: |
Expand Down Expand Up @@ -109,6 +110,61 @@ jobs:
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Check and Delete CNAME and A Records
if: always()
run: |
hosted_zone_id="Z05906472T84V7X7Q6UDY"
# Record details
cname_record_name="_5b8b09a8917e1fbb8c6aead5121fb550.testclusters.apppack.io"
a_record_name="*.testcluster.apppack.io"
# Function to check and delete a record
delete_record() {
record_name=$1
record_type=$2
echo "Checking if $record_type record '$record_name' exists ..."
record_value=$(aws route53 list-resource-record-sets --hosted-zone-id $hosted_zone_id \
--query "ResourceRecordSets[?Name == '$record_name.']" \
--output text)
if [[ -n "$record_value" ]]; then
echo "$record_type record exists, deleting..."
# Extract the actual value of the record to use in the deletion
record_actual_value=$(aws route53 list-resource-record-sets --hosted-zone-id $hosted_zone_id \
--query "ResourceRecordSets[?Name == '$record_name.'].ResourceRecords[0].Value" \
--output text)
# Delete the record
aws route53 change-resource-record-sets --hosted-zone-id "$hosted_zone_id" \
--change-batch "{
\"Changes\": [{
\"Action\": \"DELETE\",
\"ResourceRecordSet\": {
\"Name\": \"$record_name\",
\"Type\": \"$record_type\",
\"TTL\": 300,
\"ResourceRecords\": [{\"Value\": \"$record_actual_value\"}]
}
}]
}"
echo "$record_type record '$record_name' deleted successfully."
else
echo "$record_type record '$record_name' does not exist, skipping deletion."
fi
}
# Delete CNAME record
delete_record "$cname_record_name" "CNAME"
# Delete A record
delete_record "$a_record_name" "A"
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1

-
name: Destroy region
run: |
Expand Down
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,42 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [Unreleased] - TBD

### Fixed

* Verify existence of review app before resizing process with `ps resize`.

### Removed

* Region creation no longer requires Docker Hub credentials

## [4.6.2] - 2024-09-03

### Fixed

* Allow `apppack build` commands to work for non-pipeline apps.

## [4.6.1] - 2024-08-28

### Fixed

* Revert the ability to provide `APPPACK_ACCOUNT` for multiple accounts.

## [4.6.0] - 2024-08-28

### Fixed

* Prevent `Ctrl+C` from exiting the remote shell session prematurely.

### Changed

* Limits the number of custom domains to 4.
* `ps resize` raises a warning for non-existent service.
* `reviewapps` cmd optionally accepts `-c`/ `account` flag.
* Implemented a check that throws an error if neither the `-c` flag nor the `APPPACK_ACCOUNT` environment variable is set and the user has multiple accounts. This ensures that users specify an account explicitly to avoid ambiguity.

## [4.5.0] - 2024-05-16

### Changed
Expand Down
27 changes: 26 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import (
"errors"
"fmt"
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

"github.com/apppackio/apppack/auth"
Expand Down Expand Up @@ -394,6 +396,25 @@ func (a *App) GetReviewApps() ([]*ReviewApp, error) {
return reviewApps, nil
}

func (a *App) ReviewAppExists() (bool, error) {
if !a.Pipeline {
return false, fmt.Errorf("%s is not a pipeline and cannot have review apps", a.Name)
}
parameter, err := SsmParameter(a.Session, fmt.Sprintf("/apppack/pipelines/%s/review-apps/pr/%s", a.Name, *a.ReviewApp))
if err != nil {
return false, fmt.Errorf("ReviewApp named %s:%s does not exist", a.Name, *a.ReviewApp)
}
r := ReviewApp{}
err = json.Unmarshal([]byte(*parameter.Value), &r)
if err != nil {
return false, err
}
if r.Status != "created" {
return false, fmt.Errorf("ReviewApp isn't created")
}
return true, nil
}

func (a *App) ddbItem(key string) (*map[string]*dynamodb.AttributeValue, error) {
if !a.IsReviewApp() {
return ddbItem(a.Session, fmt.Sprintf("APP#%s", a.Name), key)
Expand Down Expand Up @@ -630,7 +651,11 @@ func (a *App) ConnectToEcsSession(ecsSession *ecs.Session) error {
*region,
"StartSession",
}

// Ignore Ctrl+C to keep the session active;
// reset the signal afterward so the main function
// can handle interrupts during the rest of the program's execution.
signal.Ignore(syscall.SIGINT)
defer signal.Reset(syscall.SIGINT)
sessionManagerPluginSession.ValidateInputAndStartSession(args, os.Stdout)
return nil
}
Expand Down
15 changes: 15 additions & 0 deletions app/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ func SsmParameters(sess *session.Session, path string) ([]*ssm.Parameter, error)
return parameters, nil
}

func SsmParameter(sess *session.Session, name string) (*ssm.Parameter, error) {
ssmSvc := ssm.New(sess)
input := &ssm.GetParameterInput{
Name: aws.String(name),
WithDecryption: aws.Bool(true),
}

result, err := ssmSvc.GetParameter(input)
if err != nil {
return nil, err
}

return result.Parameter, nil
}

func S3FromURL(sess *session.Session, logURL string) (*strings.Builder, error) {
s3Svc := s3.New(sess)
parts := strings.Split(strings.TrimPrefix(logURL, "s3://"), "/")
Expand Down
9 changes: 5 additions & 4 deletions cmd/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/apppackio/apppack/stacks"
"github.com/apppackio/apppack/stringslice"
"github.com/apppackio/apppack/ui"
"github.com/apppackio/apppack/utils"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -107,7 +108,7 @@ var accessCmd = &cobra.Command{
Short: "list users with access to the app",
Args: cobra.NoArgs,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ui.StartSpinner()
var err error
sess, err := adminSession(SessionDurationSeconds)
Expand All @@ -131,7 +132,7 @@ Updates the application Cloudformation stack to add access for the user.`,
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
Example: "apppack -a my-app access add [email protected] [email protected]",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
for _, email := range args {
if !validateEmail(email) {
checkErr(fmt.Errorf("%s does not appear to be a valid email address", email))
Expand Down Expand Up @@ -163,7 +164,7 @@ Updates the application Cloudformation stack to remove access for the user.`,
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
Example: "apppack -a my-app access remove [email protected] [email protected]",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
for _, email := range args {
if !validateEmail(email) {
checkErr(fmt.Errorf("%s does not appear to be a valid email address", email))
Expand Down Expand Up @@ -195,7 +196,7 @@ func init() {
"account",
"c",
"",
"AWS account ID or alias (not needed if you are only the administrator of one account)",
utils.AccountFlagHelpText,
)
accessCmd.PersistentFlags().BoolVar(
&UseAWSCredentials,
Expand Down
9 changes: 5 additions & 4 deletions cmd/admins.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/apppackio/apppack/stacks"
"github.com/apppackio/apppack/stringslice"
"github.com/apppackio/apppack/ui"
"github.com/apppackio/apppack/utils"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -57,7 +58,7 @@ var adminsCmd = &cobra.Command{
Long: "*Requires admin permissions.*",
Args: cobra.NoArgs,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, _ []string) {
ui.StartSpinner()
sess, err := adminSession(SessionDurationSeconds)
checkErr(err)
Expand All @@ -78,7 +79,7 @@ var adminsAddCmd = &cobra.Command{
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
Example: "apppack admins add [email protected] [email protected]",
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
for _, email := range args {
if !validateEmail(email) {
checkErr(fmt.Errorf("%s does not appear to be a valid email address", email))
Expand Down Expand Up @@ -108,7 +109,7 @@ var adminsRemoveCmd = &cobra.Command{
Updates the application Cloudformation stack to remove an administrators.`,
DisableFlagsInUseLine: true,
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Run: func(_ *cobra.Command, args []string) {
for _, email := range args {
if !validateEmail(email) {
checkErr(fmt.Errorf("%s does not appear to be a valid email address", email))
Expand Down Expand Up @@ -137,7 +138,7 @@ func init() {
"account",
"c",
"",
"AWS account ID or alias (not needed if you are only the administrator of one account)",
utils.AccountFlagHelpText,
)
adminsCmd.PersistentFlags().BoolVar(
&UseAWSCredentials,
Expand Down
8 changes: 8 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,14 @@ var buildStartCmd = &cobra.Command{
}
a, err := app.Init(AppName, UseAWSCredentials, duration)
checkErr(err)
if a.Pipeline {
if a.ReviewApp == nil {
err := fmt.Errorf("%q is a pipeline. You can build ReviewApps within a pipeline", a.Name)
checkErr(err)
}
_, err = a.ReviewAppExists()
checkErr(err)
}
build, err := a.StartBuild(false)
checkErr(err)
ui.Spinner.Stop()
Expand Down
5 changes: 3 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/apppackio/apppack/bridge"
"github.com/apppackio/apppack/stacks"
"github.com/apppackio/apppack/ui"
"github.com/apppackio/apppack/utils"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/logrusorgru/aurora"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -293,7 +294,7 @@ var createRegionCmd = &cobra.Command{
Short: "setup AppPack resources for an AWS region",
Long: "*Requires admin permissions.*",
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
sess, err := adminSession(MaxSessionDurationSeconds)
checkErr(err)
region := sess.Config.Region
Expand All @@ -310,7 +311,7 @@ var createRegionCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(createCmd)
createCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", "AWS account ID or alias (not needed if you are only the administrator of one account)")
createCmd.PersistentFlags().StringVarP(&AccountIDorAlias, "account", "c", "", utils.AccountFlagHelpText)
createCmd.PersistentFlags().BoolVar(&UseAWSCredentials, "aws-credentials", false, "use AWS credentials instead of AppPack.io federation")
createCmd.PersistentFlags().BoolVar(&createChangeSet, "check", false, "check stack in Cloudformation before creating")
createCmd.PersistentFlags().BoolVar(&nonInteractive, "non-interactive", false, "do not prompt for missing flags")
Expand Down
Loading

0 comments on commit caa5c8a

Please sign in to comment.