Skip to content

Commit bd3f5d0

Browse files
paskalumputun
authored andcommitted
CI: build images in PRs, don't run CI on unused files
1 parent bc200b8 commit bd3f5d0

File tree

3 files changed

+60
-21
lines changed

3 files changed

+60
-21
lines changed

.github/workflows/dockerimage.yml

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ on:
44
push:
55
branches:
66
tags:
7+
paths-ignore:
8+
- 'README.md'
9+
- 'LICENSE'
10+
- 'dk.sh'
11+
- 'Makefile'
12+
- '.github/dependabot.yml'
13+
- '.github/FUNDING.yml'
14+
pull_request:
15+
paths-ignore:
16+
- 'README.md'
17+
- 'LICENSE'
18+
- 'dk.sh'
19+
- 'Makefile'
20+
- '.github/dependabot.yml'
21+
- '.github/FUNDING.yml'
722

823
jobs:
924
build_app_image:
@@ -13,23 +28,31 @@ jobs:
1328
uses: actions/checkout@v4
1429

1530
- name: set up QEMU
31+
if: ${{ github.ref == 'refs/heads/master' }}
1632
uses: docker/setup-qemu-action@v3
1733

1834
- name: set up Docker Buildx
35+
if: ${{ github.ref == 'refs/heads/master' }}
1936
id: buildx
2037
uses: docker/setup-buildx-action@v3
2138

2239
- name: available platforms
40+
if: ${{ github.ref == 'refs/heads/master' }}
2341
run: echo ${{ steps.buildx.outputs.platforms }}
2442

25-
- name: build base.app image
43+
- name: build base.app image (no push)
44+
if: ${{ github.ref != 'refs/heads/master' }}
45+
run: |
46+
docker build base.alpine -f base.alpine/Dockerfile
47+
48+
- name: build and push master base.app image
2649
if: ${{ github.ref == 'refs/heads/master' }}
2750
env:
2851
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
2952
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
3053
USERNAME: ${{ github.actor }}
31-
GITHUB_SHA: ${{ github.sha}}
32-
GITHUB_REF: ${{ github.ref}}
54+
GITHUB_SHA: ${{ github.sha }}
55+
GITHUB_REF: ${{ github.ref }}
3356
run: |
3457
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
3558
echo GITHUB_REF - $ref
@@ -39,14 +62,14 @@ jobs:
3962
-t ghcr.io/${USERNAME}/baseimage/app:${ref} -t ${USERNAME}/baseimage:app-${ref} \
4063
base.alpine -f base.alpine/Dockerfile
4164
42-
- name: build base.app latest image
65+
- name: build and push tagged base.app latest image
4366
if: ${{ startsWith(github.ref, 'refs/tags/') }}
4467
env:
4568
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
4669
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
4770
USERNAME: ${{ github.actor }}
48-
GITHUB_SHA: ${{ github.sha}}
49-
GITHUB_REF: ${{ github.ref}}
71+
GITHUB_SHA: ${{ github.sha }}
72+
GITHUB_REF: ${{ github.ref }}
5073
run: |
5174
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
5275
echo GITHUB_REF - $ref
@@ -64,23 +87,31 @@ jobs:
6487
uses: actions/checkout@v4
6588

6689
- name: set up QEMU
90+
if: ${{ github.ref == 'refs/heads/master' }}
6791
uses: docker/setup-qemu-action@v3
6892

6993
- name: set up Docker Buildx
94+
if: ${{ github.ref == 'refs/heads/master' }}
7095
id: buildx
7196
uses: docker/setup-buildx-action@v3
7297

7398
- name: available platforms
99+
if: ${{ github.ref == 'refs/heads/master' }}
74100
run: echo ${{ steps.buildx.outputs.platforms }}
75101

76-
- name: build build.go image
102+
- name: build build.go image (no push)
103+
if: ${{ github.ref != 'refs/heads/master' }}
104+
run: |
105+
docker build build.go -f build.go/Dockerfile
106+
107+
- name: build and push master build.go image
77108
if: ${{ github.ref == 'refs/heads/master' }}
78109
env:
79110
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
80111
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
81112
USERNAME: ${{ github.actor }}
82-
GITHUB_SHA: ${{ github.sha}}
83-
GITHUB_REF: ${{ github.ref}}
113+
GITHUB_SHA: ${{ github.sha }}
114+
GITHUB_REF: ${{ github.ref }}
84115
run: |
85116
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
86117
echo GITHUB_REF - $ref
@@ -96,8 +127,8 @@ jobs:
96127
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
97128
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
98129
USERNAME: ${{ github.actor }}
99-
GITHUB_SHA: ${{ github.sha}}
100-
GITHUB_REF: ${{ github.ref}}
130+
GITHUB_SHA: ${{ github.sha }}
131+
GITHUB_REF: ${{ github.ref }}
101132
run: |
102133
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
103134
echo GITHUB_REF - $ref
@@ -115,23 +146,31 @@ jobs:
115146
uses: actions/checkout@v4
116147

117148
- name: set up QEMU
149+
if: ${{ github.ref == 'refs/heads/master' }}
118150
uses: docker/setup-qemu-action@v3
119151

120152
- name: set up Docker Buildx
153+
if: ${{ github.ref == 'refs/heads/master' }}
121154
id: buildx
122155
uses: docker/setup-buildx-action@v3
123156

124157
- name: available platforms
158+
if: ${{ github.ref == 'refs/heads/master' }}
125159
run: echo ${{ steps.buildx.outputs.platforms }}
126160

127-
- name: build base.scratch image
161+
- name: build base.scratch image (no push)
162+
if: ${{ github.ref != 'refs/heads/master' }}
163+
run: |
164+
docker build base.scratch -f base.scratch/Dockerfile
165+
166+
- name: build and push master base.scratch image
128167
if: ${{ github.ref == 'refs/heads/master' }}
129168
env:
130169
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
131170
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
132171
USERNAME: ${{ github.actor }}
133-
GITHUB_SHA: ${{ github.sha}}
134-
GITHUB_REF: ${{ github.ref}}
172+
GITHUB_SHA: ${{ github.sha }}
173+
GITHUB_REF: ${{ github.ref }}
135174
run: |
136175
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
137176
echo GITHUB_REF - $ref
@@ -147,8 +186,8 @@ jobs:
147186
GITHUB_PACKAGE_TOKEN: ${{ secrets.GITHUBPKG }}
148187
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
149188
USERNAME: ${{ github.actor }}
150-
GITHUB_SHA: ${{ github.sha}}
151-
GITHUB_REF: ${{ github.ref}}
189+
GITHUB_SHA: ${{ github.sha }}
190+
GITHUB_REF: ${{ github.ref }}
152191
run: |
153192
ref="$(echo ${GITHUB_REF} | cut -d'/' -f3)"
154193
echo GITHUB_REF - $ref

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ The container can be customized in runtime by setting environment from docker's
4040

4141
### Working with Docker from inside container
4242

43-
The `app` user is a member of the `docker` group. That allows it to interact with the Docker socket (`/var/run/docker.sock`) when it is explicitly mounted into the container. This is particularly useful for advanced use cases that require such functionality, such as monitoring other containers or accessing Docker APIs.
43+
The `app` user is a member of the `docker` group. That allows it to interact with the Docker socket (`/var/run/docker.sock`) when it is explicitly mounted into the container. This is particularly useful for advanced use cases that require such functionality, such as monitoring other containers or accessing Docker APIs.
4444

45-
Under standard usage, the Docker socket is not mounted into the container. In such cases, the docker group membership does not grant the app user any elevated privileges. The container remains secure and operates with an unprivileged user.
45+
Under standard usage, the Docker socket is not mounted into the container. In such cases, the docker group membership does not grant the app user any elevated privileges. The container remains secure and operates with an unprivileged user.
4646

4747
#### Security Implications
4848

@@ -120,9 +120,9 @@ COPY --from=build /build/app /srv/app
120120
CMD ["/srv/app", "param1", "param2"]
121121
```
122122

123-
## `dk.sh` Script
123+
## `dk.sh`
124124

125-
The `dk.sh` script is a simple script to get a shell inside containers that don't have one (like scratch-based containers). It works by temporarily copying BusyBox into the container and cleaning it up after you're done.
125+
The `dk.sh` is a simple script to get a shell inside containers that don't have one (like scratch-based containers). It works by temporarily copying BusyBox into the container and cleaning it up after you're done.
126126

127127
```
128128
./dk.sh <container_name>

base.scratch/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ghcr.io/umputun/baseimage/app:latest as prep
1+
FROM ghcr.io/umputun/baseimage/app:latest AS prep
22

33
RUN apk add -u tzdata ca-certificates build-base gcc
44

0 commit comments

Comments
 (0)