139 lines
3.8 KiB
YAML
139 lines
3.8 KiB
YAML
---
|
|
name: "Build and Publish"
|
|
|
|
on:
|
|
# run it on push to the default repository branch
|
|
push:
|
|
branches: [master]
|
|
# run it during pull request
|
|
pull_request:
|
|
|
|
jobs:
|
|
# define job to build and publish docker image
|
|
|
|
build-docker-image:
|
|
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: |
|
|
export BUILD_VERSION=v$(date +'%Y%m%d_%H%M')
|
|
echo "BUILD_VERSION=$BUILD_VERSION" >> $GITHUB_ENV
|
|
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Set up Docker Buildx
|
|
id: buildx
|
|
uses: docker/setup-buildx-action@v1
|
|
|
|
- name: Build image and save as file
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
# relative path to the place where source code with Dockerfile
|
|
# is located
|
|
context: .
|
|
file: docker/Dockerfile
|
|
# Note: tags has to be all lower-case
|
|
tags: |
|
|
glenux/teaching-boilerplate:latest
|
|
outputs: type=docker,dest=/tmp/teaching-boilerplate.image.tar
|
|
|
|
- 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: teaching-boilerplate-image
|
|
path: /tmp/
|
|
|
|
test-docker-image:
|
|
name: "Test docker image (build PDF and HTML)"
|
|
needs: build-docker-image
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- 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
|
|
|
|
- name: Build PDF for docs
|
|
run: ./scripts/gx-teaching . build-slides-pdf
|
|
|
|
- name: Build HTML for slides
|
|
run: ./scripts/gx-teaching . build-slides-html
|
|
|
|
- name: Build PDF for slides
|
|
run: ./scripts/gx-teaching . build-slides-pdf
|
|
|
|
push-docker-image:
|
|
needs: test-docker-image
|
|
name: "Push docker image to registry"
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- 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:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
|
|
|
- name: Build image and push to Docker Hub and GitHub Container Registry
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
# relative path to the place where source code with Dockerfile
|
|
# is located
|
|
context: .
|
|
file: docker/Dockerfile
|
|
# Note: tags has to be all lower-case
|
|
tags: |
|
|
glenux/teaching-boilerplate:${{ env.BUILD_VERSION }}
|
|
glenux/teaching-boilerplate:latest
|
|
# build on feature branches, push only on main branch
|
|
push: ${{ github.ref == 'refs/heads/master' }}
|
|
|
|
#
|