Skip to content

Commit

Permalink
[TASK] Update base image to latest version
Browse files Browse the repository at this point in the history
cypress/base:latest is used instead of 12.14.0.

The download URL for the Cypress binary is fixed.

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.
  • Loading branch information
astehlik committed May 9, 2023
1 parent 5bcc7d7 commit 0d18168
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 47 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"
}
18 changes: 7 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
FROM cypress/base:latest

ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
ARG cypressVersion=3.8.3

# Update package lists and bring all package up to date.
RUN apt-get update && apt-get dist-upgrade -y
COPY ./build.sh /opt/build.sh

RUN apt-get install -y curl
ENV DEBIAN_FRONTEND=noninteractive
ENV CYPRESS_INSTALL_BINARY="/opt/cypress/cypress.zip"
ENV CYPRESS_VERSION="$cypressVersion"

# Download Cypress binary
RUN mkdir /opt/cypress && curl -sS https://cdn.cypress.io/desktop/3.8.1/linux-x64/cypress.zip >/opt/cypress/cypress.zip
RUN bash /opt/build.sh "${cypressVersion}"

# Cleanup
RUN apt-get purge -y curl && apt-get --purge -y autoremove && apt-get autoclean && apt-get clean && rm -rf /var/lib/apt/lists/*

ENV CYPRESS_RUN_BINARY="/opt/cypress/cypress.zip"
RUN rm /opt/build.sh
41 changes: 41 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

set -e

cypressVersion="$1"

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 \
curl

# 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}/linux-x64/cypress.zip" >/opt/cypress/cypress.zip

# Cleanup
apt-get purge -y \
curl
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 0d18168

Please sign in to comment.