Skip to content

Fix #101 Optimiser le build Docker #6

Fix #101 Optimiser le build Docker

Fix #101 Optimiser le build Docker #6

Workflow file for this run

name: build
on:
- push
- pull_request
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: '16'
cache: 'yarn'
- name: Build
run: |
yarn install
yarn run lint
yarn run build
- uses: actions/upload-artifact@v3
with:
name: dist-${{ github.ref_name }}
path: dist
retention-days: 1
docker:
runs-on: ubuntu-latest
needs: build
if: github.event_name == 'push'
#if: github.event_name == 'push' && (github.ref_name == 'dev' || github.ref_type == 'tag')
permissions:
contents: read
packages: write
steps:
- uses: actions/download-artifact@v3
with:
name: dist-${{ github.ref_name }}
path: dist
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Define vars
run: |
IMAGE_ID=ghcr.io/${{ github.repository }}
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
VERSION=$(echo "${{ github.ref_name }}" | tr '[A-Z]' '[a-z]')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "dev" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID"
echo "VERSION=$VERSION"
# Register variables
echo "IMAGE_ID=$IMAGE_ID" >> $GITHUB_ENV
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v3
with:
push: true
tags: ${{ env.IMAGE_ID }}:${{ env.VERSION }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max