Skip to content

Commit 0993045

Browse files
committed
Add automatic docker build via github actions
1 parent 866e8b0 commit 0993045

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

.github/workflows/build.yml

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
name: CI to Docker Hub
2+
3+
on: [push, pull_request, workflow_dispatch]
4+
5+
jobs:
6+
7+
base:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
12+
- name: Check Out Repo
13+
uses: actions/checkout@v2
14+
15+
- name: Login to Docker Hub
16+
uses: docker/login-action@v1
17+
with:
18+
username: ${{ secrets.DOCKERHUB_USERNAME }}
19+
password: ${{ secrets.DOCKERHUB_TOKEN }}
20+
21+
- name: Set up Docker Buildx
22+
id: buildx
23+
uses: docker/setup-buildx-action@v1
24+
25+
- name: Get branch names
26+
id: branch-name
27+
uses: tj-actions/branch-names@v5
28+
29+
- name: Sets env vars for image_tag
30+
run: |
31+
IMAGE_TAG=${{ steps.branch-name.outputs.current_branch }}
32+
[ "$IMAGE_TAG" == "master" ] && IMAGE_TAG=latest
33+
echo "DOCKER_IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
34+
35+
- name: Build and push image
36+
uses: docker/build-push-action@v2
37+
with:
38+
context: base
39+
file: base/Dockerfile
40+
tags: bde2020/spark-base:${{env.DOCKER_IMAGE_TAG}}
41+
push: ${{ github.event_name != 'pull_request' }}
42+
43+
master_worker:
44+
runs-on: ubuntu-latest
45+
46+
strategy:
47+
fail-fast: false
48+
matrix:
49+
image: [master, worker]
50+
51+
needs: 'base'
52+
steps:
53+
54+
- name: Check Out Repo
55+
uses: actions/checkout@v2
56+
57+
- name: Login to Docker Hub
58+
uses: docker/login-action@v1
59+
with:
60+
username: ${{ secrets.DOCKERHUB_USERNAME }}
61+
password: ${{ secrets.DOCKERHUB_TOKEN }}
62+
63+
- name: Set up Docker Buildx
64+
id: buildx
65+
uses: docker/setup-buildx-action@v1
66+
67+
- name: Get branch names
68+
id: branch-name
69+
uses: tj-actions/branch-names@v5
70+
71+
- name: Sets env vars for image_tag
72+
run: |
73+
IMAGE_TAG=${{ steps.branch-name.outputs.current_branch }}
74+
[ "$IMAGE_TAG" == "master" ] && IMAGE_TAG=latest
75+
echo "DOCKER_IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
76+
77+
- name: Build and push image
78+
uses: docker/build-push-action@v2
79+
with:
80+
context: ${{ matrix.image }}
81+
file: ${{ matrix.image }}/Dockerfile
82+
tags: bde2020/spark-${{ matrix.image }}:${{env.DOCKER_IMAGE_TAG}}
83+
push: ${{ github.event_name != 'pull_request' }}
84+
85+
submit:
86+
runs-on: ubuntu-latest
87+
88+
strategy:
89+
fail-fast: false
90+
matrix:
91+
image: [submit]
92+
93+
needs: 'base'
94+
steps:
95+
96+
- name: Check Out Repo
97+
uses: actions/checkout@v2
98+
99+
- name: Login to Docker Hub
100+
uses: docker/login-action@v1
101+
with:
102+
username: ${{ secrets.DOCKERHUB_USERNAME }}
103+
password: ${{ secrets.DOCKERHUB_TOKEN }}
104+
105+
- name: Set up Docker Buildx
106+
id: buildx
107+
uses: docker/setup-buildx-action@v1
108+
109+
- name: Get branch names
110+
id: branch-name
111+
uses: tj-actions/branch-names@v5
112+
113+
- name: Sets env vars for image_tag
114+
run: |
115+
IMAGE_TAG=${{ steps.branch-name.outputs.current_branch }}
116+
[ "$IMAGE_TAG" == "master" ] && IMAGE_TAG=latest
117+
echo "DOCKER_IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
118+
119+
- name: Build and push image
120+
uses: docker/build-push-action@v2
121+
with:
122+
context: ${{ matrix.image }}
123+
file: ${{ matrix.image }}/Dockerfile
124+
tags: bde2020/spark-${{ matrix.image }}:${{env.DOCKER_IMAGE_TAG}}
125+
push: ${{ github.event_name != 'pull_request' }}
126+
127+
template:
128+
runs-on: ubuntu-latest
129+
130+
strategy:
131+
fail-fast: false
132+
matrix:
133+
template: [java, scala, python]
134+
135+
needs: 'submit'
136+
steps:
137+
138+
- name: Check Out Repo
139+
uses: actions/checkout@v2
140+
141+
- name: Login to Docker Hub
142+
uses: docker/login-action@v1
143+
with:
144+
username: ${{ secrets.DOCKERHUB_USERNAME }}
145+
password: ${{ secrets.DOCKERHUB_TOKEN }}
146+
147+
- name: Set up Docker Buildx
148+
id: buildx
149+
uses: docker/setup-buildx-action@v1
150+
151+
- name: Get branch names
152+
id: branch-name
153+
uses: tj-actions/branch-names@v5
154+
155+
- name: Sets env vars for image_tag
156+
run: |
157+
IMAGE_TAG=${{ steps.branch-name.outputs.current_branch }}
158+
[ "$IMAGE_TAG" == "master" ] && IMAGE_TAG=latest
159+
echo "DOCKER_IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
160+
161+
- name: Build and push image
162+
uses: docker/build-push-action@v2
163+
with:
164+
context: template/${{ matrix.template }}
165+
file: template/${{ matrix.template }}/Dockerfile
166+
tags: bde2020/spark-${{ matrix.template }}-template:${{env.DOCKER_IMAGE_TAG}}
167+
push: ${{ github.event_name != 'pull_request' }}

0 commit comments

Comments
 (0)