Skip to content

Commit

Permalink
Account setup (#3)
Browse files Browse the repository at this point in the history
* Add shortcut to setup account & region

* Improve output
  • Loading branch information
ipmb authored Jan 26, 2021
1 parent a9f1d4e commit b86fb1e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
22 changes: 6 additions & 16 deletions .github/workflows/functional_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:
name: Build
run: go build
-
name: Create account
run: ./apppack create account | tee account_create_output.txt
timeout-minutes: 3
name: Account Setup
run: ./apppack account-setup --dockerhub-username $DOCKERHUB_USERNAME --dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN | tee account_setup_output.txt
timeout-minutes: 6
env:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_ACCESS_TOKEN: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
Expand All @@ -33,25 +33,15 @@ jobs:
-
name: Approve account
run: |
export ROLE_ARN=$(grep AppPackRoleArn account_create_output.txt | awk '{print $2}')
export ROLE_ARN=$(grep AppPackRoleArn account_setup_output.txt | awk '{print $2}')
export ACCOUNT_ID=$(echo $ROLE_ARN | cut -d: -f5)
export EXTERNAL_ID=$(grep ExternalId account_create_output.txt | awk '{print $2}')
export EXTERNAL_ID=$(grep ExternalId account_setup_output.txt | awk '{print $2}')
python -c "import json; print(json.dumps({\"primary_id\": {\"S\": \"ACCT#$ACCOUNT_ID\"}, \"secondary_id\": {\"S\": \"-\"}, \"external_id\": {\"S\": \"$EXTERNAL_ID\"}, \"region\": {\"S\": \"us-east-1\"}, \"role_arn\": {\"S\": \"$ROLE_ARN\"}}))" > item.json
aws dynamodb put-item --table-name apppack --item file://item.json
env:
AWS_ACCESS_KEY_ID: ${{ secrets.APPPACK_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.APPPACK_AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: us-east-1
-
name: Create region
run: ./apppack create region --dockerhub-username $DOCKERHUB_USERNAME --dockerhub-access-token $DOCKERHUB_ACCESS_TOKEN
timeout-minutes: 3
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 }}
AWS_REGION: us-east-1
-
name: Create cluster
run: ./apppack create cluster --domain testclusters.apppack.io --hosted-zone-id Z05906472T84V7X7Q6UDY --instance-class t3.micro
Expand Down Expand Up @@ -125,7 +115,7 @@ jobs:
run: |
cat item.json
aws dynamodb delete-item --table-name apppack --key '{
"primary_id": {"S": "ACCT#'$(grep AppPackRoleArn account_create_output.txt | awk '{print $2}' | cut -d: -f5)'"},
"primary_id": {"S": "ACCT#'$(grep AppPackRoleArn account_setup_output.txt | awk '{print $2}' | cut -d: -f5)'"},
"secondary_id": {"S": "-"}
}'
env:
Expand Down
40 changes: 40 additions & 0 deletions cmd/accountSetup.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright © 2021 NAME HERE <EMAIL ADDRESS>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// accountSetupCmd represents the accountSetup command
var accountSetupCmd = &cobra.Command{
Use: "account-setup",
Short: "setup your AppPack account and create initial resources",
Long: "*Requires AWS credentials.*\n\nThis is a shortcut for `apppack create account && apppack create region`",
Run: func(cmd *cobra.Command, args []string) {
accountCmd.Run(cmd, []string{})
fmt.Println("")
createRegionCmd.Run(cmd, []string{})
},
}

func init() {
rootCmd.AddCommand(accountSetupCmd)
accountSetupCmd.Flags().StringP("dockerhub-username", "u", "", "Docker Hub username")
accountSetupCmd.Flags().StringP("dockerhub-access-token", "t", "", "Docker Hub Access Token (https://hub.docker.com/settings/security)")
}

0 comments on commit b86fb1e

Please sign in to comment.