ci: improve environment handling

This commit is contained in:
Glenn Y. Rolland 2021-12-21 15:45:01 +01:00
parent 375abb3146
commit 750d5052d3

View file

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