ci: push Docker image to ghcr.io #28
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build Dockerfile | |
on: push | |
jobs: | |
build: | |
runs-on: ubuntu-22.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Build Dockerfile | |
run: docker build . -t exportapp | |
- name: Start Docker container | |
run: | | |
CONTAINER_ID=$(docker run --rm -d -p 3000:3000 --net=host exportapp) | |
while ! netstat -tna | grep LISTEN | grep --silent 3000 | |
do | |
echo Waiting for Node.js server to start ... | |
sleep 5 | |
done | |
netstat -tulpen | |
docker logs "$CONTAINER_ID" | |
curl -X POST -H 'X-Image-Format: svg' -i 'http://127.0.0.1:3000/' --data '{"title": {"text": "ECharts entry example"}, "tooltip": {}, "legend": {"data": ["Sales"]}, "backgroundColor": "#ffffff", "xAxis": {"data": ["shirt","cardigan","chiffon shirt","pants","heels","socks"]}, "yAxis": {}, "series": [{"name": "Sales","type": "bar", "data": [5,20,36,10,10,20] }]}' | |
echo -e "\nStopping container ..." | |
docker stop -t 1 "$CONTAINER_ID" | |
- name: Push Docker image (edge) to registry | |
run: | | |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/echarts-node-export-server/echarts-node-export-server:edge | |
docker tag exportapp "$IMAGE_NAME" | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
docker push "$IMAGE_NAME" | |
docker logout ghcr.io | |
- name: Push Docker image (versioned tag) to registry | |
run: | | |
VERSION=$(git describe --always) | |
echo Version is $VERSION. | |
if [[ "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] | |
then | |
echo "Version seems to be a new tag." | |
else | |
echo "Version is not a new tag, exiting here." | |
exit 0 | |
fi | |
TAG=$(echo "$VERSION" | cut --characters=2- ) | |
IMAGE_NAME=ghcr.io/${{ github.repository_owner }}/echarts-node-export-server/echarts-node-export-server:$TAG | |
docker tag exportapp "$IMAGE_NAME" | |
TAG_MAJOR=$(echo "$TAG" | cut -d. -f1) | |
IMAGE_NAME_MAJOR=ghcr.io/${{ github.repository_owner }}/echarts-node-export-server/echarts-node-export-server:$TAG_MAJOR | |
docker tag exportapp "$IMAGE_NAME_MAJOR" | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | |
docker push "$IMAGE_NAME" | |
docker push "$IMAGE_NAME_MAJOR" | |
docker logout ghcr.io |