Skip to content

Commit

Permalink
Merge pull request #66 from crazy-max/remove-os-limitation
Browse files Browse the repository at this point in the history
Remove os limitation
  • Loading branch information
crazy-max committed Apr 27, 2021
2 parents 4b20628 + 7439f8b commit 28218f9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 52 deletions.
Binary file modified .github/docker-login.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ on:
- 'releases/v*'

jobs:
stop-docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: Stop docker
run: |
sudo systemctl stop docker
-
name: Login to GitHub Container Registry
uses: ./
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

dind:
runs-on: ubuntu-latest
env:
Expand Down
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@

GitHub Action to login against a Docker registry.

> :bulb: See also:
> * [setup-buildx](https://github.com/docker/setup-buildx-action) action
> * [setup-qemu](https://github.com/docker/setup-qemu-action) action
> * [build-push](https://github.com/docker/build-push-action) action
![Screenshot](.github/docker-login.png)

___
Expand All @@ -32,7 +27,6 @@ ___
* [Customizing](#customizing)
* [inputs](#inputs)
* [Keep up-to-date with GitHub Dependabot](#keep-up-to-date-with-github-dependabot)
* [Limitation](#limitation)

## Usage

Expand Down Expand Up @@ -433,7 +427,3 @@ updates:
schedule:
interval: "daily"
```

## Limitation

This action is only available for Linux [virtual environments](https://help.github.com/en/articles/virtual-environments-for-github-actions#supported-virtual-environments-and-hardware-resources).
11 changes: 0 additions & 11 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ import * as stateHelper from '../src/state-helper';

import * as core from '@actions/core';

test('errors when not run on linux platform', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'netbsd');

const coreSpy: jest.SpyInstance = jest.spyOn(core, 'setFailed');

await run();

expect(coreSpy).toHaveBeenCalledWith('Only supported on linux platform');
});

test('errors without username and password', async () => {
const platSpy = jest.spyOn(osm, 'platform');
platSpy.mockImplementation(() => 'linux');
Expand Down
26 changes: 11 additions & 15 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export async function loginStandard(registry: string, username: string, password
loginArgs.push(registry);

if (registry) {
core.info(`🔑 Logging into ${registry}...`);
core.info(`Logging into ${registry}...`);
} else {
core.info(`🔑 Logging into Docker Hub...`);
core.info(`Logging into Docker Hub...`);
}
await execm.exec('docker', loginArgs, true, password).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
core.info('🎉 Login Succeeded!');
core.info(`Login Succeeded!`);
});
}

Expand All @@ -47,27 +47,27 @@ export async function loginECR(registry: string, username: string, password: str
const accountIDs = await aws.getAccountIDs(registry);

if (await aws.isPubECR(registry)) {
core.info(`💡 AWS Public ECR detected with ${region} region`);
core.info(`AWS Public ECR detected with ${region} region`);
} else {
core.info(`💡 AWS ECR detected with ${region} region`);
core.info(`AWS ECR detected with ${region} region`);
}

process.env.AWS_ACCESS_KEY_ID = username || process.env.AWS_ACCESS_KEY_ID;
process.env.AWS_SECRET_ACCESS_KEY = password || process.env.AWS_SECRET_ACCESS_KEY;

core.info(`⬇️ Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
core.info(`Retrieving docker login command through AWS CLI ${cliVersion} (${cliPath})...`);
const loginCmds = await aws.getDockerLoginCmds(cliVersion, registry, region, accountIDs);

core.info(`🔑 Logging into ${registry}...`);
core.info(`Logging into ${registry}...`);
loginCmds.forEach((loginCmd, index) => {
execm.exec(loginCmd, [], true).then(res => {
if (res.stderr != '' && !res.success) {
throw new Error(res.stderr);
}
if (loginCmds.length > 1) {
core.info(`🎉 Login Succeeded! (${index}/${loginCmds.length})`);
core.info(`Login Succeeded! (${index}/${loginCmds.length})`);
} else {
core.info('🎉 Login Succeeded!');
core.info('Login Succeeded!');
}
});
});
Expand Down
9 changes: 2 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import * as os from 'os';
import * as core from '@actions/core';
import {getInputs, Inputs} from './context';
import * as context from './context';
import * as docker from './docker';
import * as stateHelper from './state-helper';

export async function run(): Promise<void> {
try {
if (os.platform() !== 'linux') {
throw new Error('Only supported on linux platform');
}

const {registry, username, password, logout} = getInputs();
const {registry, username, password, logout} = context.getInputs();
stateHelper.setRegistry(registry);
stateHelper.setLogout(logout);
await docker.login(registry, username, password);
Expand Down

0 comments on commit 28218f9

Please sign in to comment.