-
-
Notifications
You must be signed in to change notification settings - Fork 288
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build Docker images for every PR (#793)
* Create Dockerfile.buildx * Create pr-docker-image.yml * Move yaml in the correct folder * OZW 1.6 use the same version in all context Based on #675 Co-authored-by: Pierre-Gilles Leymarie <pierregilles.leymarie@gmail.com>
- Loading branch information
1 parent
1cdaca8
commit eab4061
Showing
2 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
name: Gladys Docker images build for PR | ||
|
||
on: | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
|
||
build-front: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Setup nodejs | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 12.x | ||
- run: cd front && npm install && npm run build | ||
- name: Upload build artifact | ||
uses: actions/upload-artifact@v1 | ||
with: | ||
name: static | ||
path: front/build | ||
|
||
docker: | ||
needs: build-front | ||
name: Build and deploy Docker images | ||
runs-on: ubuntu-latest | ||
env: | ||
# Export environment variables for all stages. | ||
DOCKER_CLI_EXPERIMENTAL: enabled # for 'docker buildx' | ||
DOCKER_USER: ${{secrets.DOCKER_USER}} | ||
DOCKER_PASSWORD: ${{secrets.DOCKER_PASSWORD}} | ||
DOCKER_REPO: gladys-dev | ||
DOCKER_PLATFORMS: > | ||
linux/amd64 | ||
linux/arm/v7 | ||
linux/arm64/v8 | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Download build artifact | ||
uses: actions/download-artifact@v1 | ||
with: | ||
name: static | ||
- name: Get PR number | ||
run: | | ||
set -vx | ||
echo "::set-env name=PR_NUMBER::$(echo $GITHUB_REF | awk 'BEGIN { FS = "/" } ; { print $3 }')" | ||
- name: Set up image tag | ||
run: | | ||
set -vx | ||
echo "::set-env name=TAG::pr${PR_NUMBER}" | ||
echo "::set-env name=DOCKER_BASE::${DOCKER_USER}/${DOCKER_REPO}" | ||
- name: Install Docker buildx | ||
run: | | ||
set -vx | ||
# Install up-to-date version of docker, with buildx support. | ||
docker_apt_repo='https://download.docker.com/linux/ubuntu' | ||
curl -fsSL "${docker_apt_repo}/gpg" | sudo apt-key add - | ||
os="$(lsb_release -cs)" | ||
sudo add-apt-repository "deb [arch=amd64] $docker_apt_repo $os stable" | ||
sudo apt-get update | ||
sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce | ||
# Enable docker daemon experimental support (for 'pull --platform'). | ||
config='/etc/docker/daemon.json' | ||
if [[ -e "$config" ]]; then | ||
sudo sed -i -e 's/{/{ "experimental": true, /' "$config" | ||
else | ||
echo '{ "experimental": true }' | sudo tee "$config" | ||
fi | ||
sudo systemctl restart docker | ||
# Install QEMU multi-architecture support for docker buildx. | ||
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes | ||
# Instantiate docker buildx builder with multi-architecture support. | ||
docker buildx create --name gladysbuilder | ||
docker buildx use gladysbuilder | ||
# Start up buildx and verify that all is OK. | ||
docker buildx inspect --bootstrap | ||
- name: Build multi-architecture Docker images with buildx | ||
run: | | ||
set -vx | ||
echo "$DOCKER_PASSWORD" \ | ||
| docker login -u="$DOCKER_USER" --password-stdin | ||
function buildx() { | ||
docker buildx build \ | ||
--platform ${DOCKER_PLATFORMS// /,} \ | ||
--push \ | ||
-f docker/Dockerfile.buildx \ | ||
"$@" \ | ||
. | ||
} | ||
buildx -t "$DOCKER_BASE:$TAG" --target gladys | ||
- name: Comment PR | ||
uses: marocchino/sticky-pull-request-comment@v1.4.0 | ||
with: | ||
header: dockercomment | ||
message: | | ||
🐳 Image is available for testing on ${{ env.DOCKER_BASE }}:${{ env.TAG }} | ||
```bash | ||
docker run -d \ | ||
--restart=always \ | ||
--privileged \ | ||
--network=host \ | ||
--name gladys${{ env.TAG }} \ | ||
-e NODE_ENV=production \ | ||
-e SERVER_PORT=80 \ | ||
-e TZ=Europe/Paris \ | ||
-e SQLITE_FILE_PATH=/var/lib/gladysassistant/gladys-pr${{ env.TAG }}.db \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v /var/lib/gladysassistant:/var/lib/gladysassistant \ | ||
-v /dev:/dev \ | ||
${{ env.DOCKER_BASE }}:${{ env.TAG }} | ||
``` | ||
number: ${{ env.PR_NUMBER }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
FROM node:lts-alpine as gladys | ||
|
||
# System dependencies | ||
RUN apk add --no-cache tzdata nmap ffmpeg sqlite openssl gzip | ||
|
||
WORKDIR /tmp | ||
|
||
# Install OZW in a dedicated RUN to benefit from Docker cache on local dev' | ||
RUN apk add --no-cache --virtual .build-deps make g++ git udev coreutils \ | ||
# Install OZW 1.6 - Commit 5d18bbfb21d8cdc61ee6baae6f478c963297dfc5 - March, 5th 2020 | ||
&& git clone https://github.com/OpenZWave/open-zwave.git \ | ||
&& cd open-zwave \ | ||
&& git checkout 5d18bbfb21d8cdc61ee6baae6f478c963297dfc5 \ | ||
&& make \ | ||
&& make install \ | ||
&& apk del .build-deps \ | ||
&& cd /tmp \ | ||
&& rm -rf /tmp/open-zwave | ||
|
||
RUN mkdir /src | ||
WORKDIR /src | ||
ADD . /src | ||
COPY ./static /src/server/static | ||
WORKDIR /src/server | ||
|
||
RUN apk add --no-cache --virtual .build-deps make gcc g++ python git libffi-dev linux-headers udev \ | ||
&& npm ci --unsafe-perm --production \ | ||
&& npm cache clean --force \ | ||
&& apk del .build-deps | ||
|
||
ENV NODE_ENV production | ||
ENV SERVER_PORT 80 | ||
|
||
# Export listening port | ||
EXPOSE 80 | ||
|
||
CMD ["npm" ,"run", "start:prod"] |