2019-11-09 14:52:28 +08:00
|
|
|
# require the secrets DOCKER_HUB_PASSWORD
|
2020-08-29 04:58:46 +08:00
|
|
|
|
|
|
|
name: Release Docker Image
|
2019-11-09 14:52:28 +08:00
|
|
|
on:
|
|
|
|
push:
|
|
|
|
tags:
|
2020-08-29 04:58:46 +08:00
|
|
|
- v*
|
2019-11-09 14:52:28 +08:00
|
|
|
jobs:
|
|
|
|
test:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2020-03-05 09:53:41 +08:00
|
|
|
- uses: actions/checkout@v2
|
2019-11-09 14:52:28 +08:00
|
|
|
- name: Run tests
|
|
|
|
run: |
|
|
|
|
if [ -f docker-compose.test.yml ]; then
|
|
|
|
docker-compose --file docker-compose.test.yml build
|
|
|
|
docker-compose --file docker-compose.test.yml run sut
|
|
|
|
else
|
|
|
|
docker build . --file Dockerfile
|
|
|
|
fi
|
|
|
|
push:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
if: github.event_name == 'push'
|
|
|
|
steps:
|
2020-08-29 04:58:46 +08:00
|
|
|
- name: Set up Checkout
|
|
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Install Buildx and QEMU
|
|
|
|
run: |
|
|
|
|
export DOCKER_BUILDKIT=1
|
|
|
|
docker build --platform=local -o . git://github.com/docker/buildx
|
|
|
|
mkdir -p ~/.docker/cli-plugins
|
|
|
|
mv buildx ~/.docker/cli-plugins/docker-buildx
|
|
|
|
docker run --rm --privileged multiarch/qemu-user-static:latest --reset -p yes --credential yes
|
|
|
|
docker buildx create --use --name build --node build --driver-opt network=host
|
|
|
|
- name: Log in to Docker Hub
|
|
|
|
env:
|
|
|
|
DOCKER_USERNAME: ${{ github.actor }}
|
|
|
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
|
|
|
run: |
|
|
|
|
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
|
|
|
|
- name: Build and push Docker image
|
|
|
|
env:
|
|
|
|
DOCKER_USERNAME: ${{ github.actor }}
|
|
|
|
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
|
|
|
|
REPOSITORY_NAME: ${{ github.repository }}
|
2019-11-09 14:52:28 +08:00
|
|
|
run: |
|
2020-08-29 04:58:46 +08:00
|
|
|
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME"
|
|
|
|
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]')
|
|
|
|
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/}
|
|
|
|
docker buildx build \
|
|
|
|
--platform "$DOCKER_IMAGE_PLATFORM" \
|
|
|
|
--output "type=image,push=true" \
|
|
|
|
--tag "$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
|
|
|
|
--tag "$DOCKER_IMAGE_NAME":latest \
|
|
|
|
--file ./Dockerfile .
|