Merge pull request #589 from zaanposni/zaanposni-patch-1 #208
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: DockerPublish | |
on: | |
push: | |
branches: | |
- "master" | |
jobs: | |
DockerPublish: | |
if: github.repository_owner == 'zaanposni' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v2 | |
- name: Determine version | |
run: | | |
VERSION=$(cat nginx/static/version.json | jq -r '.version')$($(cat nginx/static/version.json | jq -r '.pre_release') && echo "-alpha" || :) | |
echo "I found version: $VERSION" | |
echo "VERSION=$VERSION" >> $GITHUB_ENV | |
- name: Build backend | |
run: | | |
cd backend | |
docker build -t ghcr.io/${{ github.repository_owner }}/masz_backend:latest -t ghcr.io/${{ github.repository_owner }}/masz_backend:${{ env.VERSION }} . | |
- name: Build frontend | |
run: | | |
cd nginx | |
docker build -t ghcr.io/${{ github.repository_owner }}/masz_nginx:latest -t ghcr.io/${{ github.repository_owner }}/masz_nginx:${{ env.VERSION }} . | |
- name: Push images | |
run: | | |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u zaanposni --password-stdin | |
docker push ghcr.io/${{ github.repository_owner }}/masz_backend:${{ env.VERSION }} | |
docker push ghcr.io/${{ github.repository_owner }}/masz_nginx:${{ env.VERSION }} | |
if [[ ${{ env.VERSION }} != *"alpha"* ]] | |
then | |
docker push ghcr.io/${{ github.repository_owner }}/masz_backend:latest | |
docker push ghcr.io/${{ github.repository_owner }}/masz_nginx:latest | |
fi | |
- name: Calculate image sizes | |
run: | | |
SIZE_BACKEND=$(docker image inspect ghcr.io/${{ github.repository_owner }}/masz_backend:${{ env.VERSION }} | jq -r '.[0].Size' | numfmt --to=si) | |
SIZE_NGINX=$(docker image inspect ghcr.io/${{ github.repository_owner }}/masz_nginx:${{ env.VERSION }} | jq -r '.[0].Size' | numfmt --to=si) | |
echo "I found backend size: $SIZE_BACKEND" | |
echo "I found nginx size: $SIZE_NGINX" | |
echo "SIZE_BACKEND=$SIZE_BACKEND" >> $GITHUB_ENV | |
echo "SIZE_NGINX=$SIZE_NGINX" >> $GITHUB_ENV | |
- name: Send discord notification | |
env: | |
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} | |
uses: Ilshidur/action-discord@master | |
with: | |
args: "🚀 Published `masz_backend:${{ env.VERSION }}` with `${{ env.SIZE_BACKEND }}`.\n🚀 Published `masz_nginx:${{ env.VERSION }}` with `${{ env.SIZE_NGINX }}`." | |
- name: Save version in index service | |
run: | | |
if [[ ${{ env.VERSION }} != *"alpha"* ]] | |
then | |
fullhash=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository_owner }}/masz_nginx:${{ env.VERSION }}) | |
hash="${fullhash##*:}" | |
curl --location --request POST 'https://maszindex.zaanposni.com/api/v1/versions' \ | |
--header 'Content-Type: application/json' \ | |
--header 'X-GITHUB-TOKEN: ${{ secrets.INDEX_SERVICE_AUTH_HEADER }}' \ | |
--data-raw '{ | |
"imagename": "masz_nginx", | |
"tag": "${{ env.VERSION }}", | |
"hash": "'"$hash"'" | |
}' | |
fullhash=$(docker inspect --format='{{index .RepoDigests 0}}' ghcr.io/${{ github.repository_owner }}/masz_backend:${{ env.VERSION }}) | |
hash="${fullhash##*:}" | |
curl --location --request POST 'https://maszindex.zaanposni.com/api/v1/versions' \ | |
--header 'Content-Type: application/json' \ | |
--header 'X-GITHUB-TOKEN: ${{ secrets.INDEX_SERVICE_AUTH_HEADER }}' \ | |
--data-raw '{ | |
"imagename": "masz_backend", | |
"tag": "${{ env.VERSION }}", | |
"hash": "'"$hash"'" | |
}' | |
fi |