Skip to content

Commit 1178490

Browse files
committed
Add docker image DockerHub workflow
This workflow automates the generation of Docker images and publishes them to DockerHub as necessary. Signed-off-by: Jeremy Ho <jujaga@gmail.com>
1 parent 034109f commit 1178490

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: Docker Image CI
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- "v*"
9+
pull_request:
10+
jobs:
11+
docker-build:
12+
runs-on: ubuntu-latest
13+
defaults:
14+
run:
15+
working-directory: docker
16+
outputs:
17+
HAS_DOCKER_SECRETS: ${{ steps.check-secrets.outputs.HAS_DOCKER_SECRETS }}
18+
timeout-minutes: 10
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
- name: Check Workflow Secrets
23+
id: check-secrets
24+
run: |
25+
echo "::set-output name=HAS_DOCKER_SECRETS::${{ secrets.DOCKERHUB_USERNAME != '' && secrets.DOCKERHUB_TOKEN != '' }}"
26+
- name: Build the Docker image
27+
run: docker build . --file Dockerfile --tag certbot:$(date +%s)
28+
docker-publish:
29+
needs: docker-build
30+
runs-on: ubuntu-latest
31+
defaults:
32+
run:
33+
working-directory: docker
34+
timeout-minutes: 10
35+
if: github.event_name != 'pull_request' && needs.docker-build.outputs.HAS_DOCKER_SECRETS == 'true'
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v2
39+
- name: Login to DockerHub
40+
uses: docker/login-action@v1
41+
with:
42+
username: ${{ secrets.DOCKERHUB_USERNAME }}
43+
password: ${{ secrets.DOCKERHUB_TOKEN }}
44+
- name: Docker meta
45+
id: meta
46+
uses: docker/metadata-action@v3
47+
with:
48+
images: bcgovimages/certbot
49+
# Creates tags based off of branch names and semver tags
50+
tags: |
51+
type=schedule
52+
type=ref,event=branch
53+
type=ref,event=pr
54+
type=semver,pattern={{version}}
55+
type=semver,pattern={{major}}.{{minor}}
56+
type=semver,pattern={{major}}
57+
type=sha
58+
# Always updates the 'latest' tag
59+
flavor: |
60+
latest=true
61+
- name: Build and Push to DockerHub
62+
uses: docker/build-push-action@v2
63+
with:
64+
context: docker
65+
push: ${{ github.event_name != 'pull_request' }}
66+
tags: ${{ steps.meta.outputs.tags }}
67+
labels: ${{ steps.meta.outputs.labels }}
68+
- name: Inspect Docker Image
69+
run: docker image inspect bcgovimages/certbot:latest

0 commit comments

Comments
 (0)