Skip to content

Commit 9a33f7e

Browse files
authored
Adding workflow to build a container image (#4)
* Adding workflow to build a container image * fixing action version * fixing action version * fixing action version * fixing action version * fixing action version * fixing docker container tag * Adding workflow to automatically push a container image to the container registry
1 parent 5be76c8 commit 9a33f7e

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: build-container-image
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- edited
7+
- synchronize
8+
- reopened
9+
jobs:
10+
build:
11+
name: Build
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout GIT repository
15+
uses: actions/checkout@v3
16+
- name: Get the application version
17+
id: application-version
18+
run: |
19+
image_version=$(grep "^LABEL site.local.program.version=" Dockerfile | cut -d= -f2 | sed -e 's/"//g')
20+
if [ -z "${image_version}" ]; then
21+
echo "ERROR: unable to detect version number!" >&2
22+
exit 1
23+
fi
24+
echo "tag=${image_version}" >> $GITHUB_OUTPUT
25+
- name: Build container image
26+
run: |
27+
docker build . --file Dockerfile --tag oitc/modbus-server:${{steps.application-version.outputs.tag}}
28+
- name: Export container image for caching
29+
run: |
30+
docker save --output oitc-modbus-server_${{steps.application-version.outputs.tag}}.tar oitc/modbus-server:${{steps.application-version.outputs.tag}}
31+
32+
- name: Upload the container image for caching
33+
uses: actions/upload-artifact@v3.1.2
34+
with:
35+
name: modbus-server
36+
path: oitc-modbus-server_${{steps.application-version.outputs.tag}}.tar
37+
if-no-files-found: error
38+
retention-days: 1

.github/workflows/pre-commit.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ on:
33
pull_request:
44
push:
55
branches:
6-
- master
76
- main
87
jobs:
98
pre-commit:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: build-container-image
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
jobs:
7+
build:
8+
name: Push Container Image
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Download container image from cache
12+
uses: actions/download-artifact@v3.0.2
13+
with:
14+
name: modbus-server
15+
- name: Identify container version
16+
id: vars
17+
run: |
18+
container_image_file=$(find . -name "oitc-modbus-server_*.tar" -type -f | tail -1)
19+
if [ -z "${container_image_file}" ]; then
20+
echo "ERROR: Unable to get the container image file!" >&2
21+
exit 1
22+
fi
23+
container_version=$(basename ${container_image_file} | cut -d_ -f2 | sed -e 's/\.tar$//')
24+
image_name="oitc/modbus-server:${container_version}"
25+
26+
echo "container_image_file=${container_image_file}" >> $GITHUB_OUTPUT
27+
echo "container_version=${container_version}" >> $GITHUB_OUTPUT
28+
echo "image_name=${image_name}" >> $GITHUB_OUTPUT
29+
- name: Import container image
30+
run: docker import ${{steps.vars.outputs.container_image_file}}
31+
- name: Login to container registry
32+
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
33+
- name: Upload container image to container registry
34+
run: docker push ${{steps.vars.outputs.image_name}}

0 commit comments

Comments
 (0)