Skip to content

Commit

Permalink
Fix #101 Optimiser le build Docker
Browse files Browse the repository at this point in the history
  • Loading branch information
mistic100 committed Sep 16, 2023
1 parent 7f076a6 commit 141f222
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 111 deletions.
68 changes: 67 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: build
on:
- push
- pull_request
- workflow_dispatch

jobs:
build:
Expand All @@ -22,3 +21,70 @@ jobs:
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
92 changes: 0 additions & 92 deletions .github/workflows/docker-publish.yml

This file was deleted.

19 changes: 1 addition & 18 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
FROM node:16-alpine as builder

ENV NODE_ENV dev
WORKDIR /build

COPY . .

RUN echo "Arch : $(uname -m)"; \
if [ "$(uname -m)" == "aarch64" ]; then \
apk add python3 build-base gcc wget git; \
fi

RUN yarn install
RUN yarn build

# Image finale #
# ------------ #
FROM node:16-alpine as final

RUN npm install -g http-server \
Expand All @@ -25,6 +8,6 @@ EXPOSE 80
ENV NODE_ENV production

WORKDIR /www
COPY --from=builder /build/dist/ .
COPY dist/ .

CMD ["http-server", "/www", "-p 80"]

0 comments on commit 141f222

Please sign in to comment.