Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prompts for DockerHub creds #63

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,14 +49,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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ 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] - 2024-10-XX

## [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
Expand Down
7 changes: 0 additions & 7 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,11 +379,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")
}
80 changes: 10 additions & 70 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()
func (*RegionStackParameters) SetInternalFields(_ *session.Session, _ *string) error {
return nil
}

Expand Down Expand Up @@ -99,41 +55,25 @@ 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
}

func (a *RegionStack) UpdateFromFlags(flags *pflag.FlagSet) error {
return ui.FlagsToStruct(a.Parameters, flags)
}

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)
func (*RegionStack) AskQuestions(_ *session.Session) error {
return nil
}

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