ci: improve environment handling

This commit is contained in:
Glenn Y. Rolland 2021-12-21 15:45:01 +01:00
parent 3b6395c696
commit 95b3a73489

View file

@ -12,14 +12,16 @@ jobs:
# define job to build and publish docker image # define job to build and publish docker image
build-docker-image: build-docker-image:
name: Build Docker image and push to repositories name: "Build docker image"
# run only when code is compiling and tests are passing # run only when code is compiling and tests are passing
runs-on: ubuntu-latest runs-on: ubuntu-latest
# steps to perform in job # steps to perform in job
steps: steps:
- name: Set current date as env variable - name: Set current date as env variable
run: echo "BUILD_VERSION=v$(date +'%Y%m%d_%H%M')" >> $GITHUB_ENV run: |
export BUILD_VERSION=v$(date +'%Y%m%d_%H%M')
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -28,10 +30,7 @@ jobs:
id: buildx id: buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
- name: Image digest - name: Build image and save as file
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Build image and push to Docker Hub and GitHub Container Registry
uses: docker/build-push-action@v2 uses: docker/build-push-action@v2
with: with:
# relative path to the place where source code with Dockerfile # relative path to the place where source code with Dockerfile
@ -43,17 +42,22 @@ jobs:
glenux/teaching-boilerplate:latest glenux/teaching-boilerplate:latest
outputs: type=docker,dest=/tmp/teaching-boilerplate.image.tar outputs: type=docker,dest=/tmp/teaching-boilerplate.image.tar
- name: Set current date as env variable - name: Image digest
run: echo "BUILD_VERSION=v$(date +'%Y%m%d_%H%M')" >> /tmp/env run: echo ${{ steps.docker_build.outputs.digest }}
- name: Save important variables as extra.env
run: |
echo "BUILD_VERSION=$BUILD_VERSION" >> /tmp/extra.env
cat /tmp/extra.env
- name: Upload artifact - name: Upload artifact
uses: actions/upload-artifact@v2 uses: actions/upload-artifact@v2
with: with:
name: myimage name: teaching-boilerplate-image
path: /tmp/teaching-boilerplate.image.tar path: /tmp/
test-docker-image: test-docker-image:
name: Build Docker image and push to repositories name: "Test docker image (build PDF and HTML)"
needs: build-docker-image needs: build-docker-image
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -61,6 +65,21 @@ jobs:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
- name: Download artifact
uses: actions/download-artifact@v2
with:
name: teaching-boilerplate-image
path: /tmp
- name: Load environment
run: |
cat /tmp/extra.env >> $GITHUB_ENV
- name: Load image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: Build HTML for docs - name: Build HTML for docs
run: ./scripts/gx-teaching . build-docs-html run: ./scripts/gx-teaching . build-docs-html
@ -75,14 +94,28 @@ jobs:
push-docker-image: push-docker-image:
needs: test-docker-image needs: test-docker-image
name: Build Docker image and push to repositories name: "Push docker image to registry"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# setup Docker buld action - name: Download artifact
uses: actions/download-artifact@v2
with:
name: teaching-boilerplate-image
path: /tmp
- name: Load environment
run: |
cat /tmp/extra.env >> $GITHUB_ENV
- name: Set up Docker Buildx - name: Set up Docker Buildx
id: buildx id: buildx
uses: docker/setup-buildx-action@v1 uses: docker/setup-buildx-action@v1
- name: Load image
run: |
docker load --input /tmp/myimage.tar
docker image ls -a
- name: Login to DockerHub - name: Login to DockerHub
uses: docker/login-action@v1 uses: docker/login-action@v1
with: with: