-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (46 loc) · 1.77 KB
/
docker-image.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Docker
on:
push:
# Publish `main` and `stable` as Docker `latest` image.
branches:
- main
- '[0-9]+.X-stable'
# Publish `v1.2.3` tags as releases.
tags:
- 'v*'
- 'v[0-9]+.[0-9]+.[0-9]-stable'
env:
IMAGE_NAME: frinx/sample-topology
# DOCKER_CONTENT_TRUST: 1
jobs:
push:
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
#### Set tags based on source type ####
- name: Set tag for latest image
if: github.ref_type == 'branch' && startsWith(github.ref, 'refs/heads/main')
run: |
echo "IMAGE_TAG=$(echo 'latest')" >> "$GITHUB_ENV"
- name: Set tag for stable-latest image
if: github.ref_type == 'branch' && endsWith(github.ref, '-stable')
run: |
echo "IMAGE_TAG=$(echo 'stable-latest')" >> "$GITHUB_ENV"
- name: Set tag for stable-release image
if: github.ref_type == 'tag' && endsWith(github.ref, '-stable')
run: |
echo "IMAGE_TAG=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/^v//' | sed -e 's/-stable//')" >> "$GITHUB_ENV"
- name: Set tag for release image
if: ${{ github.ref_type == 'tag' && !endsWith(github.ref, '-stable') }}
run: |
echo "IMAGE_TAG=$(echo $GITHUB_REF | cut -d / -f 3 | sed -e 's/^v//')" >> "$GITHUB_ENV"
- name: Build image
run: docker build . --file Dockerfile --build-arg git_commit=$(git rev-parse HEAD) --tag $IMAGE_NAME:${IMAGE_TAG}
- name: Log into docker hub
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKER_HUB_USERNAME }} --password-stdin
- name: Push image
run: |
docker push $IMAGE_NAME:${IMAGE_TAG}