Skip to content

Commit 3d825eb

Browse files
committed
Add GitHub Actions workflow to build and push Node/Python Docker images to DockerHub
1 parent 912edc2 commit 3d825eb

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- 'dockerfile-node'
8+
- 'dockerfile-python'
9+
- 'configure-startup.sh'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- 'dockerfile-node'
14+
- 'dockerfile-python'
15+
- 'configure-startup.sh'
16+
17+
jobs:
18+
detect-changes:
19+
runs-on: ubuntu-latest
20+
outputs:
21+
node-changed: ${{ steps.filter.outputs.node }}
22+
python-changed: ${{ steps.filter.outputs.python }}
23+
startup-script-changed: ${{ steps.filter.outputs.startup }}
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: dorny/paths-filter@v2
27+
id: filter
28+
with:
29+
filters: |
30+
node:
31+
- 'dockerfile-node'
32+
python:
33+
- 'dockerfile-python'
34+
startup:
35+
- 'configure-startup.sh'
36+
37+
build-node:
38+
needs: detect-changes
39+
if: ${{ needs.detect-changes.outputs.node-changed == 'true' || needs.detect-changes.outputs.startup-script-changed == 'true' }}
40+
runs-on: ubuntu-latest
41+
steps:
42+
- uses: actions/checkout@v3
43+
- name: Set outputs
44+
id: sha
45+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
46+
- name: docker login
47+
env:
48+
DOCKER_USER: ${{secrets.DOCKER_USER}}
49+
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
50+
run: |
51+
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
52+
- name: Build the Node Docker image
53+
run: docker build . --file dockerfile-node --tag ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:node --tag ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:node-${{ steps.sha.outputs.sha_short }}
54+
- name: Docker Push Node SHA
55+
run: docker push ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:node-${{ steps.sha.outputs.sha_short }}
56+
- name: Docker Push Node
57+
run: docker push ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:node
58+
59+
build-python:
60+
needs: detect-changes
61+
if: ${{ needs.detect-changes.outputs.python-changed == 'true' || needs.detect-changes.outputs.startup-script-changed == 'true' }}
62+
runs-on: ubuntu-latest
63+
steps:
64+
- uses: actions/checkout@v3
65+
- name: Set outputs
66+
id: sha
67+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
68+
- name: docker login
69+
env:
70+
DOCKER_USER: ${{secrets.DOCKER_USER}}
71+
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}}
72+
run: |
73+
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
74+
- name: Build the Python Docker image
75+
run: docker build . --file dockerfile-python --tag ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:python --tag ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:python-${{ steps.sha.outputs.sha_short }}
76+
- name: Docker Push Python SHA
77+
run: docker push ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:python-${{ steps.sha.outputs.sha_short }}
78+
- name: Docker Push Python
79+
run: docker push ${{secrets.DOCKER_USER}}/${{ github.event.repository.name }}:python
80+

0 commit comments

Comments
 (0)