Skip to content

Commit

Permalink
Fix GHCR & add e2e tests (#44)
Browse files Browse the repository at this point in the history
* Fix GitHub Container Registry support to account for new ghcr.io paradigm
* Continue support for legacy docker.pkg.github.com
* Update npm dependencies
* Update docs
* Add e2e tests for GCR, ECR, Docker Hub & GHCR
  • Loading branch information
mr-smithers-excellent committed Feb 25, 2021
1 parent 0515366 commit 1e93d4d
Show file tree
Hide file tree
Showing 9 changed files with 12,037 additions and 1,318 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: 'Tests'
name: 'Unit Tests'

on: [push, pull_request]

Expand All @@ -7,9 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v1
uses: actions/checkout@v2

- name: Build
run: npm ci

- name: Run tests & submit coverage report
uses: paambaati/codeclimate-action@v2.7.5
env:
Expand Down
88 changes: 88 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: 'e2e Tests'

on:
schedule:
- cron: '0 8 * * *' # everyday at 8am UTC
push:
branches:
- master
pull_request:

jobs:
e2e:
name: ${{ matrix.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- name: Docker Hub
image: mrsmithers/hello-world
registry: docker.io
username: DOCKERHUB_USERNAME
password: DOCKERHUB_PASSWORD

- name: GCR
image: orbital-bank-301021/hello-world
registry: gcr.io
username: GCR_USERNAME
password: GCR_PASSWORD

- name: ECR
image: hello-world
registry: 026181534292.dkr.ecr.us-west-2.amazonaws.com

- name: GHCR Legacy
image: docker-build-push/hello-world
registry: docker.pkg.github.com
username: GH_USERNAME
password: GITHUB_TOKEN

- name: GHCR
image: hello-world
registry: ghcr.io
githubOrg: docker-action-e2e
username: GHCR_USERNAME
password: GHCR_TOKEN

steps:
- name: Check out code
uses: actions/checkout@v2

- name: Build and push Docker image
id: docker
uses: ./
with:
dockerfile: ./e2e/Dockerfile
image: ${{ matrix.image }}
tags: latest, ${{ github.run_id }}
registry: ${{ matrix.registry }}
githubOrg: ${{ matrix.githubOrg }}
username: ${{ secrets[matrix.username] }}
password: ${{ secrets[matrix.password] }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

- name: Verify Docker image
run: |
docker pull ${{ steps.docker.outputs.imageFullName }}:${{ github.run_id }}
docker image inspect ${{ steps.docker.outputs.imageFullName }}:${{ github.run_id }}
- name: Raise issue on failure
if: failure()
uses: actions/github-script@v3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: 'e2e test failure',
body: 'Tests failed in run ' `https://github.com/mr-smithers-excellent/docker-build-push/actions/runs/${context.runId}`,
labels: ['Triage']
})
- name: Dump context
if: always()
uses: crazy-max/ghaction-dump-context@v1
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,36 @@ env:
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
```

### GitHub Docker Registry
### GitHub Container Registry

* GitHub recently [migrated their container registry](https://docs.github.com/en/packages/guides/migrating-to-github-container-registry-for-docker-images) from docker.pkg.github.com to ghcr.io
* It is assumed you'll be pushing the image to a repo inside your GitHub organization, unless you set `githubOrg`
* Provide the image name in `github-repo-name/image-name` format
* If using ghcr.io, provide the image name in `ghcr.io/OWNER/IMAGE_NAME` format
* If using docker.pkg.github.com, provide the image name in `docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME` format
* Provide either the `${{ github.actor }}` or an alternate username for Docker login (with associated token below)
* Pass the default GitHub Actions token or custom secret with [proper push permissions](https://help.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token#permissions-for-the-github_token)
* Pass the default GitHub Actions token or custom secret with [proper push permissions](https://docs.github.com/en/packages/guides/pushing-and-pulling-docker-images#authenticating-to-github-container-registry)

#### New ghcr.io

```yaml
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: github-repo/image-name
image: image-name
registry: ghcr.io
githubOrg: override-org # optional
username: ${{ secrets.GHCR_USERNAME }}
password: ${{ secrets.GHCR_TOKEN }}
```

#### Legacy docker.pkg.github.com

```yaml
uses: mr-smithers-excellent/docker-build-push@v5
with:
image: github-repo/image-name
registry: docker.pkg.github.com
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
password: ${{ secrets.GITHUB_TOKEN }}
```

## Tagging the image using GitOps
Expand Down
10 changes: 7 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,7 @@ const core = __webpack_require__(470);
const docker = __webpack_require__(95);
const github = __webpack_require__(790);

const GITHUB_REGISTRY = 'docker.pkg.github.com';
const GITHUB_REGISTRY_URLS = ['docker.pkg.github.com', 'ghcr.io'];

let image;
let registry;
Expand Down Expand Up @@ -1672,11 +1672,15 @@ const processInputs = () => {
githubOwner = core.getInput('githubOrg') || github.getDefaultOwner();
};

const isGithubRegistry = () => {
return GITHUB_REGISTRY_URLS.includes(registry);
};

// Create the full Docker image name with registry prefix (without tag)
const createFullImageName = () => {
let imageFullName;
if (registry === GITHUB_REGISTRY) {
imageFullName = `${GITHUB_REGISTRY}/${githubOwner.toLowerCase()}/${image}`;
if (isGithubRegistry()) {
imageFullName = `${registry}/${githubOwner.toLowerCase()}/${image}`;
} else {
imageFullName = `${registry}/${image}`;
}
Expand Down
3 changes: 3 additions & 0 deletions e2e/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM alpine

RUN echo "Hello world!"
Loading

0 comments on commit 1e93d4d

Please sign in to comment.