ci: improve environment handling
This commit is contained in:
parent
375abb3146
commit
750d5052d3
1 changed files with 46 additions and 13 deletions
59
.github/workflows/build-and-publish.yml
vendored
59
.github/workflows/build-and-publish.yml
vendored
|
@ -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:
|
||||||
|
|
Loading…
Reference in a new issue