Merge pull request #520 from kallydev/docker
This commit is contained in:
commit
5f0a66c23c
3 changed files with 65 additions and 41 deletions
29
.github/workflows/docker-build.yaml
vendored
Normal file
29
.github/workflows/docker-build.yaml
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
name: Build Docker Image
|
||||||
|
on: [push, pull_request]
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Set up Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
- name: Install Buildx and QEMU
|
||||||
|
run: |
|
||||||
|
export DOCKER_BUILDKIT=1
|
||||||
|
docker build --platform=local -o . git://github.com/docker/buildx
|
||||||
|
mkdir -p ~/.docker/cli-plugins
|
||||||
|
mv buildx ~/.docker/cli-plugins/docker-buildx
|
||||||
|
docker run --rm --privileged multiarch/qemu-user-static:latest --reset -p yes --credential yes
|
||||||
|
docker buildx create --use --name build --node build --driver-opt network=host
|
||||||
|
- name: Build Docker image
|
||||||
|
env:
|
||||||
|
DOCKER_USERNAME: ${{ github.actor }}
|
||||||
|
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
|
||||||
|
REPOSITORY_NAME: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME"
|
||||||
|
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]')
|
||||||
|
docker buildx build \
|
||||||
|
--platform "$DOCKER_IMAGE_PLATFORM" \
|
||||||
|
--output "type=image,push=false" \
|
||||||
|
--tag "$DOCKER_IMAGE_NAME":latest \
|
||||||
|
--file ./Dockerfile .
|
71
.github/workflows/docker-push.yml
vendored
71
.github/workflows/docker-push.yml
vendored
|
@ -1,23 +1,15 @@
|
||||||
# require the secrets DOCKER_HUB_PASSWORD
|
# require the secrets DOCKER_HUB_PASSWORD
|
||||||
|
|
||||||
name: Docker Push
|
name: Release Docker Image
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
tags:
|
tags:
|
||||||
- '*'
|
- v*
|
||||||
env:
|
|
||||||
IMAGE_NAME: yacd
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: |
|
run: |
|
||||||
if [ -f docker-compose.test.yml ]; then
|
if [ -f docker-compose.test.yml ]; then
|
||||||
|
@ -26,37 +18,38 @@ jobs:
|
||||||
else
|
else
|
||||||
docker build . --file Dockerfile
|
docker build . --file Dockerfile
|
||||||
fi
|
fi
|
||||||
|
|
||||||
push:
|
push:
|
||||||
needs: test
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: github.event_name == 'push'
|
if: github.event_name == 'push'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- name: Set up Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
- name: Build image
|
- name: Install Buildx and QEMU
|
||||||
run: docker build . --file Dockerfile --tag image
|
|
||||||
|
|
||||||
- name: Log into registry
|
|
||||||
run: echo "${{ secrets.DOCKER_HUB_PASSWORD }}" | docker login -u ${{ github.actor }} --password-stdin
|
|
||||||
|
|
||||||
- name: Push image
|
|
||||||
run: |
|
run: |
|
||||||
IMAGE_ID=haishanh/$IMAGE_NAME
|
export DOCKER_BUILDKIT=1
|
||||||
|
docker build --platform=local -o . git://github.com/docker/buildx
|
||||||
# Strip git ref prefix from version
|
mkdir -p ~/.docker/cli-plugins
|
||||||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
|
mv buildx ~/.docker/cli-plugins/docker-buildx
|
||||||
|
docker run --rm --privileged multiarch/qemu-user-static:latest --reset -p yes --credential yes
|
||||||
# Strip "v" prefix from tag name
|
docker buildx create --use --name build --node build --driver-opt network=host
|
||||||
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
|
- name: Log in to Docker Hub
|
||||||
|
env:
|
||||||
# Use Docker `latest` tag convention
|
DOCKER_USERNAME: ${{ github.actor }}
|
||||||
[ "$VERSION" == "master" ] && VERSION=latest
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
|
||||||
|
run: |
|
||||||
echo IMAGE_ID=$IMAGE_ID
|
echo "${DOCKER_PASSWORD}" | docker login --username ${DOCKER_USERNAME} --password-stdin
|
||||||
echo VERSION=$VERSION
|
- name: Build and push Docker image
|
||||||
|
env:
|
||||||
docker tag image $IMAGE_ID:$VERSION
|
DOCKER_USERNAME: ${{ github.actor }}
|
||||||
docker push $IMAGE_ID:$VERSION
|
DOCKER_IMAGE_PLATFORM: linux/amd64,linux/arm/v7,linux/arm64
|
||||||
|
REPOSITORY_NAME: ${{ github.repository }}
|
||||||
|
run: |
|
||||||
|
IFS='/' read -ra repository_name_array <<<"$REPOSITORY_NAME"
|
||||||
|
DOCKER_IMAGE_NAME=$(echo $DOCKER_USERNAME/${repository_name_array[1]} | tr '[:upper:]' '[:lower:]')
|
||||||
|
DOCKER_IMAGE_VERSION=${GITHUB_REF#refs/*/}
|
||||||
|
docker buildx build \
|
||||||
|
--platform "$DOCKER_IMAGE_PLATFORM" \
|
||||||
|
--output "type=image,push=true" \
|
||||||
|
--tag "$DOCKER_IMAGE_NAME":"$DOCKER_IMAGE_VERSION" \
|
||||||
|
--tag "$DOCKER_IMAGE_NAME":latest \
|
||||||
|
--file ./Dockerfile .
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
FROM node:alpine AS builder
|
FROM node:alpine AS builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN yarn && yarn run build
|
# Using yarn to install dependencies in CI will cause network timeout
|
||||||
|
# Refer to https://github.com/date-fns/date-fns/issues/1004
|
||||||
|
RUN yarn config set network-timeout 300000 && yarn && yarn run build
|
||||||
|
|
||||||
FROM nginx:alpine
|
FROM nginx:alpine
|
||||||
RUN rm -rf /usr/share/nginx/html/*
|
RUN rm -rf /usr/share/nginx/html/*
|
||||||
|
|
Loading…
Reference in a new issue