Skip to content

Commit

Permalink
Remove prompts for DockerHub creds
Browse files Browse the repository at this point in the history
They are no longer needed with the latest Codebuild builder.
  • Loading branch information
ipmb committed May 29, 2024
1 parent 742f131 commit 44b1bcf
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 83 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/databases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ jobs:
run: |
./bin/apppack create region --region us-east-2 \
--aws-credentials \
--dockerhub-username $DOCKERHUB_USERNAME \
--dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN \
--non-interactive
./bin/apppack create cluster --region us-east-2 \
--aws-credentials \
--domain testclusters.apppack.io \
--non-interactive
timeout-minutes: 15
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
standard-mysql:
Expand Down
4 changes: 0 additions & 4 deletions .github/workflows/functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,10 @@ jobs:
--aws-credentials \
--region us-east-1 \
--create-region \
--dockerhub-username $DOCKERHUB_USERNAME \
--dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN \
--domain testclusters.apppack.io \
--non-interactive
timeout-minutes: 20
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
-
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ 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

### Removed

* Region creation no longer requires Docker Hub credentials

## [4.5.0] - 2024-05-16

### Changed
Expand Down
7 changes: 0 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,4 @@ func init() {
createDatabaseCmd.Flags().Int("max-allocated-storage", stacks.DefaultDatabaseStackParameters.MaxAllocatedStorage, "maximum storage allocated on-demand in GB (does not apply to Aurora engines)")

createCmd.AddCommand(createRegionCmd)
createRegionCmd.Flags().String("dockerhub-username", "", "Docker Hub username")
createRegionCmd.Flags().String("dockerhub-access-token", "", "Docker Hub Access Token (https://hub.docker.com/settings/security)")
// All flags need to be added to `createCluster` as well so it can call this cmd
createClusterCmd.Flags().String("dockerhub-username", "", "Docker Hub username")
createClusterCmd.Flags().String("dockerhub-access-token", "", "Docker Hub Access Token (https://hub.docker.com/settings/security)")
createClusterCmd.Flags().MarkHidden("dockerhub-username")
createClusterCmd.Flags().MarkHidden("dockerhub-access-token")
}
76 changes: 8 additions & 68 deletions stacks/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

"github.com/AlecAivazis/survey/v2"
"github.com/apppackio/apppack/ui"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
Expand All @@ -15,61 +14,18 @@ import (
)

type RegionStackParameters struct {
DockerhubUsername string `flag:"dockerhub-username"`
DockerhubAccessToken string `flag:"dockerhub-access-token"`
}

func (p *RegionStackParameters) Import(parameters []*cloudformation.Parameter) error {
return CloudformationParametersToStruct(p, parameters)
}

func (p *RegionStackParameters) ToCloudFormationParameters() ([]*cloudformation.Parameter, error) {
cfnParams, err := StructToCloudformationParameters(p)
if err != nil {
return nil, err
}
// pop DockerhubAccessToken from the list of parameters
// it is stored in SSM instead of getting directly passed to CloudFormation
accessTokenIndex := -1

for i, param := range cfnParams {
if *param.ParameterKey == "DockerhubAccessToken" {
accessTokenIndex = i

break
}
}
if accessTokenIndex == -1 {
return nil, fmt.Errorf("DockerhubAccessToken not found in parameters")
}
return append(cfnParams[:accessTokenIndex], cfnParams[accessTokenIndex+1:]...), nil
return StructToCloudformationParameters(p)
}

// SetInternalFields updates fields that aren't exposed to the user
func (p *RegionStackParameters) SetInternalFields(sess *session.Session, name *string) error {
ui.StartSpinner()
parameterName := "/apppack/account/dockerhub-access-token"
ssmSvc := ssm.New(sess)
// Verify that DockerhubAccessToken exists if it's not set
if p.DockerhubAccessToken == "" {
logrus.WithFields(logrus.Fields{"parameter": parameterName}).Debug("getting parameter from SSM")
_, err := ssmSvc.GetParameter(&ssm.GetParameterInput{Name: &parameterName})
ui.Spinner.Stop()
return err
}
_, err := ssmSvc.PutParameter(&ssm.PutParameterInput{
Name: &parameterName,
Value: &p.DockerhubAccessToken,
Type: aws.String("SecureString"),
Tags: []*ssm.Tag{
{Key: aws.String("apppack:region"), Value: name},
{Key: aws.String("apppack"), Value: aws.String("true")},
},
})
if err != nil {
return err
}
ui.Spinner.Stop()
return nil
}

Expand Down Expand Up @@ -99,10 +55,16 @@ func (*RegionStack) PreDelete(_ *session.Session) error {
}

func (*RegionStack) PostDelete(sess *session.Session, _ *string) error {
// Stacks before `formations/5.8.0` used this parameter
ssmSvc := ssm.New(sess)
_, err := ssmSvc.DeleteParameter(&ssm.DeleteParameterInput{
Name: aws.String("/apppack/account/dockerhub-access-token"),
})
// Ignore error if the parameter doesn't exist
if err != nil && !strings.Contains(err.Error(), "ParameterNotFound") {
logrus.WithError(err).Debug("dockerhub-access-token parameter does not exist")
return nil
}
return err
}

Expand All @@ -111,29 +73,7 @@ func (a *RegionStack) UpdateFromFlags(flags *pflag.FlagSet) error {
}

func (a *RegionStack) AskQuestions(_ *session.Session) error {
questions := []*ui.QuestionExtra{
{
Verbose: "What is your Docker Hub username?",
HelpText: "App images will be created using base images from Docker Hub. " +
"To avoid hitting rate limits during the build process, a free Docker Hub account is required. " +
"See https://docs.docker.com/docker-hub/download-rate-limit/ for more info.",
Question: &survey.Question{
Name: "DockerhubUsername",
Prompt: &survey.Input{Message: "Docker Hub Username", Default: a.Parameters.DockerhubUsername},
Validate: survey.Required,
},
},
{
Verbose: "What is your Docker Hub access token?",
HelpText: "An access token for your Docker Hub account can be generated at https://hub.docker.com/settings/security.",
Question: &survey.Question{
Name: "DockerhubAccessToken",
Prompt: &survey.Password{Message: "Docker Hub Access Token"},
Validate: survey.Required,
},
},
}
return ui.AskQuestions(questions, a.Parameters)
return nil
}

func (*RegionStack) StackName(name *string) *string {
Expand Down

0 comments on commit 44b1bcf

Please sign in to comment.