Skip to content

Commit

Permalink
[TASK] Update base image and Node.js
Browse files Browse the repository at this point in the history
Ubuntu 18.04 is used instead of 16.04

Node.js version 16 is used instead of 8

The build is restructed: a shell script is used to
reduce image layer amount and size.

Reformat files with Prettier / shfmt.

A verify step is added to the GitHub action.

# Conflicts:
#	Dockerfile
  • Loading branch information
astehlik committed May 9, 2023
1 parent 91cd1a1 commit 6ddc3da
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 85 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[{*.sh,Dockerfile}]
binary_next_line = true
switch_case_indent = true
space_redirects = false
86 changes: 50 additions & 36 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,57 @@ name: Build and push to Docker Hub

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: ['*']
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: ["*"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Log in to Docker Hub
# Uses v1.10.0, sha1 is used for better security
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Get docker tag for master
if: github.ref == 'refs/heads/master'
shell: bash
run: echo "DOCKER_TAG=latest" >> $GITHUB_ENV

- name: Get branch for all other branches
if: github.ref != 'refs/heads/master'
shell: bash
run: echo "DOCKER_TAG=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV

- name: Build and push Docker image
# Uses v2.7.0, sha1 is used for better security
uses: docker/build-push-action@a66e35b9cbcf4ad0ea91ffcaf7bbad63ad9e0229
with:
context: .
push: true
tags: intera/ci-cypress:${{ env.DOCKER_TAG }},intera/docker-ci-cypress:${{ env.DOCKER_TAG }}
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: |
intera/ci-cypress
intera/docker-ci-cypress
# generate Docker tags based on the following events/attributes
tags: |
type=raw,priority=700,value=latest,enable={{ is_default_branch }}
type=ref,event=branch
- name: Log in to Docker Hub
# Uses v2.1.0, sha1 is used for better security
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: .
load: true
tags: |
${{ steps.meta.outputs.tags }}
intera/ci-cypress:local
- name: Verify Cypress
run: |
docker run --rm -v "$(pwd)/verify.sh":/opt/verify.sh intera/ci-cypress:local bash /opt/verify.sh
- name: Push Docker image
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"editor.defaultFormatter": null,
"[dockerfile]": {
"editor.defaultFormatter": "foxundermoon.shell-format"
},
"shellformat.flag": "--binary-next-line --case-indent"
}
58 changes: 9 additions & 49 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,54 +1,14 @@
FROM ubuntu:16.04
FROM ubuntu:18.04

# Install dependencies for install scripts.
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
curl
ARG cypressVersion=3.0.3
ARG nodeVersion=16

# Add Yarn repo
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
COPY ./build.sh /opt/build.sh

# Add Chrome repo
RUN curl -sS https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list
ENV DEBIAN_FRONTEND=noninteractive
ENV CYPRESS_INSTALL_BINARY="/opt/cypress/cypress.zip"
ENV CYPRESS_VERSION="$cypressVersion"

# Update package lists and bring all package up to date.
RUN apt-get update \
&& apt-get dist-upgrade -y
RUN bash /opt/build.sh "${cypressVersion}" "${nodeVersion}"

# Install Yarn
RUN apt-get install -y yarn

# Install Node.js
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& apt-get install -y nodejs

# Install Cypress dependencies (separate commands to avoid time outs)
RUN apt-get install -y \
libgtk2.0-0
RUN apt-get install -y \
libnotify-dev
RUN apt-get install -y \
libgconf-2-4 \
libnss3 \
libxss1
RUN apt-get install -y \
libasound2 \
xvfb

RUN apt-get install -y dbus-x11 google-chrome-stable

# Download Cypress binary
RUN mkdir /opt/cypress \
&& curl -sS https://cdn.cypress.io/desktop/3.0.3/linux64/cypress.zip > /opt/cypress/cypress.zip

# Cleanup
RUN apt-get purge -y \
apt-transport-https \
curl \
&& apt-get --purge -y autoremove \
&& apt-get autoclean \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN rm /opt/build.sh
61 changes: 61 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

set -e

cypressVersion="$1"
nodeVersion="$2"

echo "Building for Cypress version ${cypressVersion}"

# Update package lists and bring all package up to date.
apt-get update
apt-get dist-upgrade -y

# Install dependencies for install scripts.
apt-get install -y \
apt-transport-https \
curl \
gnupg

# Install Node.js
curl -sL "https://deb.nodesource.com/setup_${nodeVersion}.x" | bash -
apt-get install -y nodejs

# Install Yarn
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | tee /usr/share/keyrings/yarnkey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | tee /etc/apt/sources.list.d/yarn.list
apt-get update
apt-get install -y yarn

# Install Chrome
curl -sL https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor | tee /usr/share/keyrings/googlekey.gpg >/dev/null
echo "deb [signed-by=/usr/share/keyrings/googlekey.gpg] https://dl.google.com/linux/chrome/deb/ stable main" >/etc/apt/sources.list.d/google.list

# Install Cypress dependencies
apt-get install -y \
libgtk2.0-0 \
libgtk-3-0 \
libgbm-dev \
libnotify-dev \
libgconf-2-4 \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb

# Download Cypress binary
mkdir /opt/cypress
curl -sS "https://cdn.cypress.io/desktop/${cypressVersion}/linux64/cypress.zip" >/opt/cypress/cypress.zip

# Cleanup
apt-get purge -y \
apt-transport-https \
curl \
gnupg \
lsb-release
apt-get --purge -y autoremove
apt-get autoclean
apt-get clean
rm -rf /var/lib/apt/lists/*
9 changes: 9 additions & 0 deletions verify.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -e

cd "$HOME"

npm install "cypress@${CYPRESS_VERSION}"

npx cypress verify

0 comments on commit 6ddc3da

Please sign in to comment.