Skip to content

Update Dockerfile (major) #91

Update Dockerfile (major)

Update Dockerfile (major) #91

name: Docker
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
# TODO: Change variable to your image's name.
IMAGE_NAME: bluecherrydvr
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-20.04
# services:
# mariadb:
# image: mariadb:latest
# options: >-
# --health-cmd "mysqladmin ping -h localhost
# ports:
# - 3306
# options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10
# env:
# MYSQL_USER: root
# MYSQL_PASSWORD: root
# MYSQL_DATABASE: test
# MYSQL_ROOT_PASSWORD: root
# options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
steps:
- uses: actions/checkout@v3
- uses: shogo82148/actions-setup-mysql@v1
with:
mysql-version: "5.7"
- run: sudo apt-get install -y mysql-client && mysql --version && mysql -uroot -e 'SELECT version()' && echo -e "Alert testing MYSQL connection...\n\n" && mysqladmin ping -h"127.0.0.1" -P"3306"
# - uses: actions/checkout@v2
# - name: Verify MySQL connection from host
# run: sudo apt-get install -y mysql-client
- name: Verify MariaDB connection
env:
PORT: ${{ job.services.mariadb.ports[3306] }}
run: |
while ! mysqladmin ping -h"127.0.0.1" -P"3306" --silent; do
sleep 1
done
- 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
echo -e "testing MYSQL connection..."\n\n && mysqladmin ping -h"127.0.0.1" -P"3306" -u root -proot ; echo $?
docker build . --file server/Dockerfile
fi
# Push image to GitHub Packages.
# See also https://docs.docker.com/docker-hub/builds/
push:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file server/Dockerfile --tag $IMAGE_NAME
- name: Log into GitHub Container Registry
# TODO: Create a PAT with `read:packages` and `write:packages` scopes and save it as an Actions secret `CR_PAT`
run: echo "${{ secrets.CR_PAT }}" | docker login https://ghcr.io -u ${{ github.actor }} --password-stdin
- name: Push image to GitHub Container Registry
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "master" ] && VERSION=latest
echo IMAGE_ID=$IMAGE_ID
echo VERSION=$VERSION
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
docker push $IMAGE_ID:$VERSION