Skip to content

Commit 509e20d

Browse files
Robadams cicd (#1)
Add automatic generation and pushing of docker images. If a branch is being pushed, then docker image pcesapps-dev is updated with the latest and timestamp tags. If a tag is being pushed, then docker image pcesapps-beta is updated with the latest, timestamp, and git tag tags. If the docker-build.sh script is invoked by hand, with no arguments, then pcseapps-test is updated with a timestamp tag.
1 parent 1d73d3e commit 509e20d

File tree

3 files changed

+92
-19
lines changed

3 files changed

+92
-19
lines changed

.github/workflows/docker-image.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
tags: [ "v*" ]
7+
pull_request:
8+
branches: [ "main" ]
9+
10+
jobs:
11+
12+
build:
13+
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: update image vars
18+
run: |
19+
if [ "$GITHUB_REF_TYPE" = "tag" ]
20+
then
21+
echo IMAGE_TYPE=beta
22+
echo IMAGE_TAG=$GITHUB_REF_NAME
23+
else
24+
echo IMAGE_TYPE=dev
25+
echo IMAGE_TAG=
26+
fi >> $GITHUB_ENV
27+
- name: Login to GitHub Container Registry
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.actor }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- uses: actions/checkout@v4
35+
- name: Build the Docker image
36+
run: cd beta && ./docker-build.sh $IMAGE_TYPE $IMAGE_TAG

beta/Dockerfile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ FROM golang:bookworm AS builder
1313
RUN ldd --version
1414
WORKDIR /build
1515
COPY . .
16-
RUN cd bld-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./bld.go
17-
RUN cd bld-dir && ./bld -is args-bld
18-
RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtExec.go
19-
RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtDesc.go
20-
RUN cd sim-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./sim.go
16+
# RUN cd bld-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./bld.go
17+
# RUN cd bld-dir && ./bld -is args-bld
18+
# RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtExec.go
19+
# RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtDesc.go
20+
# RUN cd sim-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./sim.go
2121

2222
# Production phase
2323
FROM debian:bookworm
24-
RUN apt update && apt upgrade -y && apt install -y \
25-
python3 \
26-
python3-tk \
27-
python3-pil \
28-
python3-pil.imagetk vim-nox \
29-
python3-yaml \
30-
python3-matplotlib
24+
#RUN apt update && apt upgrade -y && apt install -y \
25+
# python3 \
26+
# python3-tk \
27+
# python3-pil \
28+
# python3-pil.imagetk vim-nox \
29+
# python3-yaml \
30+
# python3-matplotlib
3131
WORKDIR /app
3232
COPY --from=builder /build/. .

beta/docker-build.sh

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,46 @@
1-
#!/bin/sh -ex
1+
#!/bin/bash -e
22
# Copyright 2024 The Board of Trustees of the University of Illinois
33

4-
TAG=ghcr.io/iti/pcesapps-beta:v0.1.1
5-
TAG2=ghcr.io/iti/pcesapps-beta:latest
6-
cp ../go.mod ../go.sum .
7-
docker build --no-cache -t $TAG -t $TAG2 .
8-
docker push $TAG
9-
docker push $TAG2
4+
# Usage: docker-build.sh [suffix [version ...]]
5+
# Builds a docker image
6+
# and pushes it with the tags
7+
# ghcr.io/iti/pocesapps-$suffix:$version1
8+
# ghcr.io/iti/pocesapps-$suffix:$version2
9+
# ...
10+
# The default value of "$suffix" is test.
11+
# Additionally, versions of $(date) and "latest"
12+
# are always created
13+
#
14+
# To test your code from the command line:
15+
# ./docker-build.sh
16+
# ./docker-run.sh
17+
# That creates ghcr.io.iti/pcesapps-test:latest
18+
#
19+
# Whenever you git push a branch, the ci/cd runs:
20+
# ./docker-build.sh dev
21+
# This creates ghcr.io/iti/pcesappos-dev:latest
22+
#
23+
# Whever your git push a tag, the ci/cd runs:
24+
# ./docker-build.shy beta $tag
25+
# This creates ghcr.io/iti/pcesapps-beta:$tag
26+
27+
#pfx="ghcr.io/illinoisadams/doc-test"
28+
pfx="ghcr.io/iti/pcesapps"
29+
30+
now=$(date -u +%F-%H-%M-%S)
31+
if "$1" = ""
32+
then
33+
image="$pfx-test"
34+
latest=
35+
else
36+
image="$pfx-$1"
37+
shift
38+
latest=( "latest" "$@" )
39+
fi
40+
41+
docker build --no-cache -t "$image:$now" .
42+
docker push "$image:$now"
43+
for v in "${latest[@]}" ; do
44+
docker tag "$image:$now" "$image:$v"
45+
docker push "$image:$v"
46+
done

0 commit comments

Comments
 (0)