From e10589323db6bb036fc12bbfc230d015c54f34e4 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:26:19 -0500 Subject: [PATCH 01/15] ci/cd test --- .github/workflows/docker-image.yml | 19 +++++++++++++ beta/Dockerfile | 24 ++++++++-------- beta/docker-build.sh | 44 +++++++++++++++++++++++++----- 3 files changed, 68 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..ba729c4 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,19 @@ +name: Docker Image CI + +on: + push: + branches: [ "*" ] + tags: [ "v*" ] + pull_request: + branches: [ "main" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Build the Docker image + run: beta/docker-build.sh test diff --git a/beta/Dockerfile b/beta/Dockerfile index 5700cf0..4629280 100644 --- a/beta/Dockerfile +++ b/beta/Dockerfile @@ -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/. . diff --git a/beta/docker-build.sh b/beta/docker-build.sh index ab3c382..7afce23 100755 --- a/beta/docker-build.sh +++ b/beta/docker-build.sh @@ -1,9 +1,39 @@ -#!/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) +image="$pfx-"${1:-"test"} +latest=( ${1:+"latest"} "$@" ) + +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 From 63060a2d67664085eeb47bf06ccf0d8cd7b05fd7 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:28:16 -0500 Subject: [PATCH 02/15] ci/cd --- .github/workflows/docker-image.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index ba729c4..5bc326b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -16,4 +16,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build the Docker image - run: beta/docker-build.sh test + run: cd beta && ./docker-build.sh test From 7b85b45b64af457037f49a82e4eda2178fb2ba71 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:31:37 -0500 Subject: [PATCH 03/15] ci/cd --- .github/workflows/docker-image.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 5bc326b..db14c71 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,6 +14,11 @@ jobs: runs-on: ubuntu-latest steps: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} - uses: actions/checkout@v4 - name: Build the Docker image run: cd beta && ./docker-build.sh test From 4ab6e391b5a202fc2663dd373c60c61efd2a7515 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:34:49 -0500 Subject: [PATCH 04/15] ci/cd --- .github/workflows/docker-image.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index db14c71..44567e5 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,11 +14,13 @@ jobs: runs-on: ubuntu-latest steps: - - name: Login to Docker Hub + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + 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 test From d0c11f44d8b8f966a64c97de7775f40ab59e7856 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:41:50 -0500 Subject: [PATCH 05/15] ci/cd --- .github/workflows/docker-image.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 44567e5..d020e3e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,6 +14,13 @@ jobs: runs-on: ubuntu-latest steps: + - name: Branch name + id: branch_name + run: | + echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} + echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} + echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} + - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -23,4 +30,4 @@ jobs: - uses: actions/checkout@v4 - name: Build the Docker image - run: cd beta && ./docker-build.sh test + run: cd beta && ./docker-build.sh test ${{ steps.branch_name.outputs.SOURCE_TAG }} From 4fd04344d9201defe3da9230e8db6d0b03aceaed Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 11:53:02 -0500 Subject: [PATCH 06/15] ci/cd --- .github/workflows/docker-image.yml | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d020e3e..c32e1db 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,13 +14,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Branch name - id: branch_name - run: | - echo ::set-output name=SOURCE_NAME::${GITHUB_REF#refs/*/} - echo ::set-output name=SOURCE_BRANCH::${GITHUB_REF#refs/heads/} - echo ::set-output name=SOURCE_TAG::${GITHUB_REF#refs/tags/} - - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: @@ -30,4 +23,4 @@ jobs: - uses: actions/checkout@v4 - name: Build the Docker image - run: cd beta && ./docker-build.sh test ${{ steps.branch_name.outputs.SOURCE_TAG }} + run: cd beta && ./docker-build.sh test $GITHUB_REF_NAME From 2931f1fffc0c3e5272e6481aab8ddbee6a832db5 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 12:06:46 -0500 Subject: [PATCH 07/15] ci/cd --- .github/workflows/docker-image.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c32e1db..bd1b377 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,6 +13,10 @@ jobs: runs-on: ubuntu-latest + env: + - IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) + - IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) + steps: - name: Login to GitHub Container Registry uses: docker/login-action@v3 @@ -23,4 +27,4 @@ jobs: - uses: actions/checkout@v4 - name: Build the Docker image - run: cd beta && ./docker-build.sh test $GITHUB_REF_NAME + run: cd beta && ./docker-build.sh $IMAGE_TYPE $IMAGE_TAG From d2dbff4bac19c996c9a56bdc743fbb34bb7a336d Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 12:07:23 -0500 Subject: [PATCH 08/15] ci/cd --- .github/workflows/docker-image.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index bd1b377..45fe001 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -14,8 +14,8 @@ jobs: runs-on: ubuntu-latest env: - - IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) - - IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) + IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) + IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) steps: - name: Login to GitHub Container Registry From 9a82ff9496ffbf3e4f48357e05078f0daee17b4a Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 12:09:05 -0500 Subject: [PATCH 09/15] ci/cd --- .github/workflows/docker-image.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 45fe001..eca9e02 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -18,6 +18,8 @@ jobs: IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) steps: + - name: env + run: env - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: From e993124315b1b01320af0d5b15f10457bf879af2 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 12:19:00 -0500 Subject: [PATCH 10/15] ci/cd --- .github/workflows/docker-image.yml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index eca9e02..e50a9ce 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,11 +13,21 @@ jobs: runs-on: ubuntu-latest - env: - IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) - IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) + #env: + # IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) + # IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) steps: + - name: update image vars + run: | + if [ "$GITHUB_REF_TYPE" = "tag" ] + then + echo IMAGE_TYPE=xbeta + echo IMAGE_TAG=$GITHUB_REF_NAME + else + echo IMAGE_TYPE=dev + echo IMAGE_TAG= + fi >> $GITHUB_ENV - name: env run: env - name: Login to GitHub Container Registry From 28f7c39f4259a4a494be9022e13bb50e620c19db Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 14:37:44 -0500 Subject: [PATCH 11/15] fix --- beta/docker-build.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/beta/docker-build.sh b/beta/docker-build.sh index 7afce23..8e57c4c 100755 --- a/beta/docker-build.sh +++ b/beta/docker-build.sh @@ -28,8 +28,15 @@ pfx="ghcr.io/illinoisadams/doc-test" pfx="ghcr.io/iti/pcesapps" now=$(date -u +%F-%H-%M-%S) -image="$pfx-"${1:-"test"} -latest=( ${1:+"latest"} "$@" ) +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" From b9023cf4a37eb90ced2049669935315e53278506 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Mon, 5 Aug 2024 14:43:01 -0500 Subject: [PATCH 12/15] cicd --- .github/workflows/docker-image.yml | 8 +------- beta/docker-build.sh | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index e50a9ce..7a5e2a0 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -13,23 +13,17 @@ jobs: runs-on: ubuntu-latest - #env: - # IMAGE_TYPE: $(test "$GITHUB_REF_TYPE" = "tag" && echo xbeta || echo dev) - # IMAGE_TAG: $(test "$GITHUB_REF_TYPE" = "tag" && echo $GITHUB_REF_NAME) - steps: - name: update image vars run: | if [ "$GITHUB_REF_TYPE" = "tag" ] then - echo IMAGE_TYPE=xbeta + echo IMAGE_TYPE=beta echo IMAGE_TAG=$GITHUB_REF_NAME else echo IMAGE_TYPE=dev echo IMAGE_TAG= fi >> $GITHUB_ENV - - name: env - run: env - name: Login to GitHub Container Registry uses: docker/login-action@v3 with: diff --git a/beta/docker-build.sh b/beta/docker-build.sh index 8e57c4c..4af56b6 100755 --- a/beta/docker-build.sh +++ b/beta/docker-build.sh @@ -24,7 +24,7 @@ # ./docker-build.shy beta $tag # This creates ghcr.io/iti/pcesapps-beta:$tag -pfx="ghcr.io/illinoisadams/doc-test" +#pfx="ghcr.io/illinoisadams/doc-test" pfx="ghcr.io/iti/pcesapps" now=$(date -u +%F-%H-%M-%S) From 889c6ca68d43ed81191e6eef836b37c64163b310 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Tue, 6 Aug 2024 09:06:13 -0500 Subject: [PATCH 13/15] bug fixes for cicd --- beta/Dockerfile | 24 ++++++++++++------------ beta/docker-build.sh | 5 +++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/beta/Dockerfile b/beta/Dockerfile index 4629280..5700cf0 100644 --- a/beta/Dockerfile +++ b/beta/Dockerfile @@ -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/. . diff --git a/beta/docker-build.sh b/beta/docker-build.sh index 4af56b6..4f4791d 100755 --- a/beta/docker-build.sh +++ b/beta/docker-build.sh @@ -28,10 +28,11 @@ pfx="ghcr.io/iti/pcesapps" now=$(date -u +%F-%H-%M-%S) -if "$1" = "" + +if [ "$1" = "" ] then image="$pfx-test" - latest= + latest=( ) else image="$pfx-$1" shift From ecaf1db3927bb3b978a90d3ff48211f36de67cbf Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Tue, 6 Aug 2024 09:14:17 -0500 Subject: [PATCH 14/15] more cicd fixes --- beta/docker-build.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/beta/docker-build.sh b/beta/docker-build.sh index 4f4791d..b09d9d1 100755 --- a/beta/docker-build.sh +++ b/beta/docker-build.sh @@ -39,6 +39,7 @@ else latest=( "latest" "$@" ) fi +cp ../go.mod ../go.sum . docker build --no-cache -t "$image:$now" . docker push "$image:$now" for v in "${latest[@]}" ; do From 7094694d6e6de8f4f4479965b1a4d0b5eb929ec4 Mon Sep 17 00:00:00 2001 From: Rob Adams Date: Tue, 6 Aug 2024 09:45:07 -0500 Subject: [PATCH 15/15] Add source label so docker image points to source URL. --- beta/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/beta/Dockerfile b/beta/Dockerfile index 5700cf0..cf38699 100644 --- a/beta/Dockerfile +++ b/beta/Dockerfile @@ -9,6 +9,7 @@ # Build phase FROM golang:bookworm AS builder +LABEL org.opencontainers.image.source = "https://github.com/ITI/pcesapps" # Next line is just for debug RUN ldd --version WORKDIR /build