Skip to content

Commit

Permalink
Robadams cicd (#1)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
illinoisrobert authored Aug 5, 2024
1 parent 1d73d3e commit 509e20d
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 19 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Docker Image CI

on:
push:
branches: [ "*" ]
tags: [ "v*" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

steps:
- name: update image vars
run: |
if [ "$GITHUB_REF_TYPE" = "tag" ]
then
echo IMAGE_TYPE=beta
echo IMAGE_TAG=$GITHUB_REF_NAME
else
echo IMAGE_TYPE=dev
echo IMAGE_TAG=
fi >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- uses: actions/checkout@v4
- name: Build the Docker image
run: cd beta && ./docker-build.sh $IMAGE_TYPE $IMAGE_TAG
24 changes: 12 additions & 12 deletions beta/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ FROM golang:bookworm AS builder
RUN ldd --version
WORKDIR /build
COPY . .
RUN cd bld-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./bld.go
RUN cd bld-dir && ./bld -is args-bld
RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtExec.go
RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtDesc.go
RUN cd sim-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./sim.go
# RUN cd bld-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./bld.go
# RUN cd bld-dir && ./bld -is args-bld
# RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtExec.go
# RUN cd db && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build cnvrtDesc.go
# RUN cd sim-dir && CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./sim.go

# Production phase
FROM debian:bookworm
RUN apt update && apt upgrade -y && apt install -y \
python3 \
python3-tk \
python3-pil \
python3-pil.imagetk vim-nox \
python3-yaml \
python3-matplotlib
#RUN apt update && apt upgrade -y && apt install -y \
# python3 \
# python3-tk \
# python3-pil \
# python3-pil.imagetk vim-nox \
# python3-yaml \
# python3-matplotlib
WORKDIR /app
COPY --from=builder /build/. .
51 changes: 44 additions & 7 deletions beta/docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
#!/bin/sh -ex
#!/bin/bash -e
# Copyright 2024 The Board of Trustees of the University of Illinois

TAG=ghcr.io/iti/pcesapps-beta:v0.1.1
TAG2=ghcr.io/iti/pcesapps-beta:latest
cp ../go.mod ../go.sum .
docker build --no-cache -t $TAG -t $TAG2 .
docker push $TAG
docker push $TAG2
# Usage: docker-build.sh [suffix [version ...]]
# Builds a docker image
# and pushes it with the tags
# ghcr.io/iti/pocesapps-$suffix:$version1
# ghcr.io/iti/pocesapps-$suffix:$version2
# ...
# The default value of "$suffix" is test.
# Additionally, versions of $(date) and "latest"
# are always created
#
# To test your code from the command line:
# ./docker-build.sh
# ./docker-run.sh
# That creates ghcr.io.iti/pcesapps-test:latest
#
# Whenever you git push a branch, the ci/cd runs:
# ./docker-build.sh dev
# This creates ghcr.io/iti/pcesappos-dev:latest
#
# Whever your git push a tag, the ci/cd runs:
# ./docker-build.shy beta $tag
# This creates ghcr.io/iti/pcesapps-beta:$tag

#pfx="ghcr.io/illinoisadams/doc-test"
pfx="ghcr.io/iti/pcesapps"

now=$(date -u +%F-%H-%M-%S)
if "$1" = ""
then
image="$pfx-test"
latest=
else
image="$pfx-$1"
shift
latest=( "latest" "$@" )
fi

docker build --no-cache -t "$image:$now" .
docker push "$image:$now"
for v in "${latest[@]}" ; do
docker tag "$image:$now" "$image:$v"
docker push "$image:$v"
done

0 comments on commit 509e20d

Please sign in to comment.