-
Notifications
You must be signed in to change notification settings - Fork 27
126 lines (124 loc) · 5.58 KB
/
github-build.yml
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: Nagios Build
# This workflow is triggered on pushes to the repository.
# Taken from tutorial
# https://github.com/gitschooldude/hello
# https://www.youtube.com/watch?v=-xIXFxuZCMI
# https://github.com/marketplace/actions/docker-setup-buildx
# https://github.com/marketplace/actions/docker-login
# https://stackoverflow.com/questions/58033366/how-to-get-current-branch-within-github-actions/58034787
on: [push]
jobs:
nagios-build:
runs-on: ubuntu-latest
steps:
- name: Print all github.* variables
id: step_one_print_all
run: |
echo "github.action : ${{ github.action }}"
echo "github.action_path : ${{ github.action_path }}"
echo "github.actor : ${{ github.actor }}"
echo "github.base_ref : ${{ github.base_ref }}"
echo 'github.event : ${{ toJson(github.event) }}'
echo "github.event_name : ${{ github.event_name }}"
echo "github.event_path : ${{ github.event_path }}"
echo "github.head_ref : ${{ github.head_ref }}"
echo "github.job : ${{ github.job }}"
echo "github.ref : ${{ github.ref }}"
echo "github.repository : ${{ github.repository }}"
echo "github.repository_owner : ${{ github.repository_owner }}"
echo "github.run_id : ${{ github.run_id }}"
echo "github.run_number : ${{ github.run_number }}"
echo "github.sha : ${{ github.sha }}"
echo "github.token : ${{ github.token }}"
echo "github.workflow : ${{ github.workflow }}"
echo "github.workspace : ${{ github.workspace }}"
echo "my docker tag: ${{ env.action_mytag }}"
- name: Set the value of a the Docker tag for branches other than master
id: step_two_branches_all
if: ${{ (startsWith( github.ref, 'refs/heads') == true) && (github.ref != 'refs/heads/master') }}
run: |
echo "action_mytag=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
- name: Set the value of the Docker tag for git tags
id: step_set_docker_tag_for_git_tags
if: ${{ startsWith( github.ref, 'refs/tags') == true}}
run: |
echo "action_mytag=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Set the value of the Docker tag for master branch
id: step_branch_master
if: ${{ github.ref == 'refs/heads/master' }}
run: |
echo "action_mytag=latest" >> $GITHUB_ENV
- name: Print the Docker tag value which will be used
id: step_print_docker_tag
run: |
echo "My docker tag will be: ${{ env.action_mytag }}"
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Checkout
uses: actions/checkout@v4
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Available platforms
run: echo ${{ steps.buildx.outputs.platforms }}
-
name: Cache Docker layers for this Git branch
uses: actions/cache@v4
id: cache
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.ref }}
restore-keys: |
${{ runner.os }}-buildx-${{ github.ref }}
- name: Docker Buildx (build and cache)
run: |
docker buildx build \
--progress plain \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \
--label "gitCommit=${{ github.sha }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--tag ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \
--output "type=image,push=false" .
- name: 'Docker Buildx: Push to Dockerhub'
run: |
echo "== This branch is : ${GITHUB_REF}"
echo "Will push image ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to DockerHub"
docker buildx build \
--progress plain \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \
--label "gitCommit=${{ github.sha }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--tag ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \
--output "type=image,push=true" .
- name: 'Docker Buildx: Push to GitHub Container Registry'
run: |
echo "== This branch is : ${GITHUB_REF}"
echo "Will push image ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} to GitHub Container Registry"
docker buildx build \
--progress plain \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--platform linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64 \
--label "gitCommit=${{ github.sha }}" \
--label "org.opencontainers.image.revision=${{ github.sha }}" \
--tag ghcr.io/${GITHUB_ACTOR}/nagios:${{ env.action_mytag }} \
--output "type=image,push=true" .
- name: Inspect image
run: |
docker buildx imagetools inspect ${GITHUB_ACTOR}/nagios:${{ env.action_mytag }}