Skip to content

Commit

Permalink
Merge pull request #3 from netsells/feature/tidy-docker-login
Browse files Browse the repository at this point in the history
Tidies up docker login
  • Loading branch information
spamoom authored Jul 29, 2020
2 parents df18ce0 + 28c28b9 commit 67159df
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ netsells
aws:ssm:start-session Configures your machine for SSM SSH connections
docker:aws:deploy-update Updates task definition and service
docker:aws:push Pushes docker-compose created images to ECR.
docker:build Builds docker-compose ready for prod.
docker:aws:login Logs into docker via the AWS account
docker:aws:push Pushes docker-compose created images to ECR
docker:build Builds docker-compose ready for prod
```

## Netsells File Reference
Expand Down
2 changes: 1 addition & 1 deletion app/Commands/DockerBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DockerBuildCommand extends Command
*
* @var string
*/
protected $description = 'Builds docker-compose ready for prod.';
protected $description = 'Builds docker-compose ready for prod';

/** @var Helpers $helpers */
protected $helpers;
Expand Down
63 changes: 63 additions & 0 deletions app/Commands/DockerLoginCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace App\Commands;

use App\Helpers\Helpers;
use App\Helpers\NetsellsFile;
use App\Exceptions\ProcessFailed;
use Symfony\Component\Process\Process;
use LaravelZero\Framework\Commands\Command;
use Symfony\Component\Console\Input\InputOption;

class DockerLoginCommand extends Command
{
/**
* The signature of the command.
*
* @var string
*/
protected $signature = 'docker:aws:login';

/**
* The description of the command.
*
* @var string
*/
protected $description = 'Logs into docker via the AWS account';

/** @var Helpers $helpers */
protected $helpers;

public function __construct(Helpers $helpers)
{
$this->helpers = $helpers;
parent::__construct();
}

public function configure()
{
$this->setDefinition($this->helpers->aws()->commonConsoleOptions());
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$requiredBinaries = ['docker', 'aws'];

if ($this->helpers->checks()->checkAndReportMissingBinaries($this, $requiredBinaries)) {
return 1;
}

$loginSuccessful = $this->helpers->aws()->ecs()->authenticateDocker($this);

if (!$loginSuccessful) {
return 1;
}

$this->info("Logged into docker.");
}
}
2 changes: 1 addition & 1 deletion app/Commands/DockerPushCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DockerPushCommand extends Command
*
* @var string
*/
protected $description = 'Pushes docker-compose created images to ECR.';
protected $description = 'Pushes docker-compose created images to ECR';

/** @var Helpers $helpers */
protected $helpers;
Expand Down
4 changes: 2 additions & 2 deletions app/Helpers/Aws/Ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function authenticateDocker(Command $command): bool
try {
$this->aws->helpers->process()->withCommand([
'docker', 'login',
"--username=AWS",
"--password={$password}",
'--username', 'AWS',
'--password', $password,
"{$awsAccountId}.dkr.ecr.{$awsRegion}.amazonaws.com"
])
->run();
Expand Down

0 comments on commit 67159df

Please sign in to comment.