Skip to content

Commit 2ce3a0e

Browse files
author
Mike Coutermarsh
authored
Merge pull request actions#179 from josh/docker
Add Docker push to GitHub Package Registry
2 parents 00e9f4c + 8c3d01f commit 2ce3a0e

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

ci/docker-push.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Docker
2+
3+
on:
4+
push:
5+
# Publish `master` as Docker `latest` image.
6+
branches:
7+
- master
8+
9+
# Publish `v1.2.3` tags as releases.
10+
tags:
11+
- v*
12+
13+
# Run tests for any PRs.
14+
pull_request:
15+
16+
env:
17+
# TODO: Change variable to your image's name.
18+
IMAGE_NAME: image
19+
20+
jobs:
21+
# Run tests.
22+
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
23+
test:
24+
runs-on: ubuntu-latest
25+
26+
steps:
27+
- uses: actions/checkout@v1
28+
29+
- name: Run tests
30+
run: |
31+
if [ -f docker-compose.test.yml ]; then
32+
docker-compose --file docker-compose.test.yml build
33+
docker-compose --file docker-compose.test.yml run sut
34+
else
35+
docker build . --file Dockerfile
36+
fi
37+
38+
# Push image to GitHub Package Registry.
39+
# See also https://docs.docker.com/docker-hub/builds/
40+
push:
41+
# Ensure test job passes before pushing image.
42+
needs: test
43+
44+
runs-on: ubuntu-latest
45+
if: github.event_name == 'push'
46+
47+
steps:
48+
- uses: actions/checkout@v1
49+
50+
- name: Build image
51+
run: docker build . --file Dockerfile --tag image
52+
53+
- name: Log into registry
54+
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u ${{ github.actor }} --password-stdin
55+
56+
- name: Push image
57+
run: |
58+
IMAGE_ID=docker.pkg.github.com/${{ github.repository }}/$IMAGE_NAME
59+
60+
# Strip git ref prefix from version
61+
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
62+
63+
# Strip "v" prefix from tag name
64+
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
65+
66+
# Use Docker `latest` tag convention
67+
[ "$VERSION" == "master" ] && VERSION=latest
68+
69+
echo IMAGE_ID=$IMAGE_ID
70+
echo VERSION=$VERSION
71+
72+
docker tag image $IMAGE_ID:$VERSION
73+
docker push $IMAGE_ID:$VERSION
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "Docker push",
3+
"description": "Build, test and push Docker image to GitHub Package Registry.",
4+
"iconName": "docker",
5+
"categories": ["Dockerfile"]
6+
}

0 commit comments

Comments
 (0)