-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
376 additions
and
99 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 |
---|---|---|
@@ -1,19 +1,22 @@ | ||
name: CI/CD | ||
|
||
env: | ||
IMAGE_NAME: weleda-webcenter-text-export | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
- "**" | ||
tags: | ||
- "*.*.*" | ||
paths: | ||
- .github/workflows/ci-cd.yml | ||
# - "docker/**" | ||
- "docker/**" | ||
- "public/**" | ||
- "src/**" | ||
# - .dockerignore | ||
- .dockerignore | ||
- .yarnrc.yml | ||
# - docker-compose.build.yml | ||
# - Dockerfile | ||
- Dockerfile | ||
- package.json | ||
- tsconfig.json | ||
- yarn.lock | ||
|
@@ -26,96 +29,277 @@ jobs: | |
test: | ||
runs-on: ubuntu-latest | ||
|
||
# https://github.com/marketplace/actions/build-and-push-docker-images#local-registry | ||
services: | ||
registry: | ||
image: registry:2 | ||
ports: | ||
- 5000:5000 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v1 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: "14" | ||
|
||
# https://github.com/actions/cache/blob/main/examples.md#node---yarn-2 | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)" | ||
|
||
- uses: actions/cache@v2 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
- name: Cache local yarn repository | ||
id: yarn-cache | ||
uses: actions/cache@v2 | ||
with: | ||
# A list of files, directories, and wildcard patterns to cache and restore. See @actions/glob for supported patterns. | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
# An explicit key for restoring and saving the cache | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
- name: Install dependencies | ||
run: yarn install --immutable | ||
|
||
- name: Build | ||
run: yarn run build | ||
|
||
- name: Run tests | ||
run: yarn run test | ||
|
||
- name: Build | ||
run: yarn run build | ||
- name: Setup QEMU | ||
id: qemu | ||
uses: docker/setup-qemu-action@v1 | ||
# with: | ||
# # QEMU static binaries Docker image | ||
# image: tonistiigi/binfmt:latest # optional, default is "tonistiigi/binfmt" | ||
# # Platforms to install (e.g. arm64,riscv64,arm) | ||
# platforms: all # optional, default is "all" | ||
|
||
- name: Setup Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
# Buildx version. | ||
# version: latest # optional | ||
# Sets the builder driver to be used | ||
# driver: docker-container # optional, default is "docker-container" | ||
# List of additional driver-specific options (eg. image=moby/buildkit:master) | ||
driver-opts: network=host # optional | ||
# Flags for buildkitd daemon (since buildx v0.3.0) | ||
# buildkitd-flags: # optional | ||
# Sets up docker build command as an alias to docker buildx | ||
# install: false # optional, default is "false" | ||
# Switch to this builder instance | ||
# use: true # optional, default is "true" | ||
# Optional address for docker socket or context from docker context ls | ||
# endpoint: # optional | ||
|
||
# https://github.com/marketplace/actions/build-and-push-docker-images#leverage-github-cache | ||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
# A list of files, directories, and wildcard patterns to cache and restore. See @actions/glob for supported patterns. | ||
path: /tmp/.buildx-cache | ||
# An explicit key for restoring and saving the cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Build (Docker) | ||
uses: docker/build-push-action@v2 | ||
with: | ||
# Builder instance (see setup-buildx action) | ||
# builder: # optional | ||
# Build's context is the set of files located in the specified PATH or URL | ||
# context: . # optional, default is git context | ||
# Path to the Dockerfile | ||
# file: ./Dockerfile # optional, default is "Dockerfile" | ||
# List of build-time variables | ||
# build-args: # optional | ||
# List of metadata for an image | ||
# labels: # optional | ||
# List of tags | ||
tags: localhost:5000/name/app:latest # optional | ||
# Always attempt to pull a newer version of the image | ||
# pull: false # optional, default is "false" | ||
# Sets the target stage to build | ||
# target: # optional | ||
# List of extra privileged entitlement (eg. network.host,security.insecure) | ||
# allow: # optional | ||
# Do not use cache when building the image | ||
# no-cache: false # optional, default is "false" | ||
# List of target platforms for build | ||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 # optional | ||
# Load is a shorthand for --output=type=docker | ||
# load: false # optional, default is "false" | ||
# Push is a shorthand for --output=type=registry | ||
push: true # optional, default is "false" | ||
# List of output destinations (format: type=local,dest=path) | ||
# outputs: # optional | ||
# List of external cache sources (eg. type=local,src=path/to/dir) | ||
cache-from: type=local,src=/tmp/.buildx-cache # optional | ||
# List of cache export destinations (eg. type=local,dest=path/to/dir) | ||
cache-to: type=local,dest=/tmp/.buildx-cache # optional | ||
# List of secrets to expose to the build (eg. key=value, GIT_AUTH_TOKEN=mytoken) | ||
# secrets: # optional | ||
|
||
- name: Inspect | ||
run: | | ||
docker buildx imagetools inspect localhost:5000/name/app:latest | ||
publish: | ||
deploy: | ||
needs: test | ||
|
||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' && github.repository == 'D3strukt0r/weleda-webcenter-text-export' | ||
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/develop') && github.repository == 'D3strukt0r/weleda-webcenter-text-export' | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v1 | ||
with: | ||
node-version: "14" | ||
|
||
- name: Setup Travis DPL | ||
# https://github.com/actions/starter-workflows/blob/main/ci/docker-publish.yml | ||
# https://github.com/docker/build-push-action#complete-workflow | ||
- name: Prepare | ||
id: prep | ||
run: | | ||
sudo apt update | ||
sudo apt install -y ruby | ||
sudo gem install dpl --pre | ||
DOCKER_IMAGE="$(echo "${{ secrets.DOCKER_USERNAME }}/$IMAGE_NAME" | tr '[A-Z]' '[a-z]')" | ||
# https://github.com/actions/cache/blob/main/examples.md#node---yarn-2 | ||
- name: Get yarn cache directory path | ||
id: yarn-cache-dir-path | ||
run: echo "::set-output name=dir::$(yarn config get cacheFolder)" | ||
# Strip git ref prefix from version | ||
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') | ||
# Rename branches which stand for latest or similar | ||
if [ "$VERSION" = '${{ github.event.repository.default_branch }}' ]; then | ||
VERSION=latest | ||
elif [ "$VERSION" = 'develop' ]; then | ||
VERSION=nightly | ||
else | ||
# Rename my/branch to my-branch | ||
VERSION=$(echo "$VERSION" | sed -r 's#/+#-#g') | ||
fi | ||
# Strip "v" prefix from tag name | ||
if [[ "${{ github.ref }}" == refs/tags/* ]]; then | ||
VERSION=$(echo $VERSION | sed -e 's/^v//') | ||
fi | ||
# Create tags | ||
TAGS="${DOCKER_IMAGE}:${VERSION}" | ||
if [[ $VERSION =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then | ||
MINOR=${VERSION%.*} | ||
MAJOR=${MINOR%.*} | ||
TAGS="$TAGS,${DOCKER_IMAGE}:${MINOR},${DOCKER_IMAGE}:${MAJOR},${DOCKER_IMAGE}:latest" | ||
# elif [ "${{ github.event_name }}" = 'push' ]; then | ||
# TAGS="$TAGS,${DOCKER_IMAGE}:sha-${GITHUB_SHA::8}" | ||
fi | ||
echo ::set-output name=version::${VERSION} | ||
echo ::set-output name=tags::${TAGS} | ||
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ') | ||
- uses: actions/cache@v2 | ||
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) | ||
- name: Setup QEMU | ||
id: qemu | ||
uses: docker/setup-qemu-action@v1 | ||
# with: | ||
# # QEMU static binaries Docker image | ||
# image: tonistiigi/binfmt:latest # optional, default is "tonistiigi/binfmt" | ||
# # Platforms to install (e.g. arm64,riscv64,arm) | ||
# platforms: all # optional, default is "all" | ||
|
||
- name: Setup Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v1 | ||
with: | ||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} | ||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-yarn- | ||
# Buildx version. | ||
version: latest # optional | ||
# Sets the builder driver to be used | ||
# driver: docker-container # optional, default is "docker-container" | ||
# List of additional driver-specific options (eg. image=moby/buildkit:master) | ||
# driver-opts: | # optional | ||
# image=moby/buildkit:master | ||
# network=host | ||
# Flags for buildkitd daemon (since buildx v0.3.0) | ||
# buildkitd-flags: # optional | ||
# Sets up docker build command as an alias to docker buildx | ||
# install: false # optional, default is "false" | ||
# Switch to this builder instance | ||
# use: true # optional, default is "true" | ||
# Optional address for docker socket or context from docker context ls | ||
# endpoint: # optional | ||
|
||
- name: Install dependencies | ||
run: yarn install --immutable | ||
# https://github.com/marketplace/actions/build-and-push-docker-images#leverage-github-cache | ||
- name: Cache Docker layers | ||
uses: actions/cache@v2 | ||
with: | ||
# A list of files, directories, and wildcard patterns to cache and restore. See @actions/glob for supported patterns. | ||
path: /tmp/.buildx-cache | ||
# An explicit key for restoring and saving the cache | ||
key: ${{ runner.os }}-buildx-${{ github.sha }} | ||
# An ordered list of keys to use for restoring the cache if no cache hit occurred for key | ||
restore-keys: | | ||
${{ runner.os }}-buildx- | ||
- name: Build | ||
run: yarn run build | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
# Server address of Docker registry. If not set then will default to Docker Hub | ||
# registry: # optional, default is docker registry | ||
# Username used to log against the Docker registry | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
# Password or personal access token used to log against the Docker registry | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
# Log out from the Docker registry at the end of a job | ||
# logout: true # optional, default is "true" | ||
|
||
# https://github.com/travis-ci/dpl#github-pages | ||
- name: Deploy to Github Pages (Production) | ||
if: github.ref == 'refs/heads/master' | ||
run: | | ||
dpl pages git \ | ||
--repo D3strukt0r/weleda-webcenter-text-export-prod \ | ||
--token ${{ secrets.PAT }} \ | ||
--target_branch master \ | ||
--keep_history \ | ||
--allow_empty_commit \ | ||
--verbose \ | ||
--local_dir build \ | ||
--fqdn webcenter-text-export.manuele-vaccari.ch | ||
- name: Deploy to Github Pages (Development) | ||
if: github.ref == 'refs/heads/develop' | ||
run: | | ||
dpl pages git \ | ||
--repo D3strukt0r/weleda-webcenter-text-export-dev \ | ||
--token ${{ secrets.PAT }} \ | ||
--target_branch master \ | ||
--keep_history \ | ||
--allow_empty_commit \ | ||
--verbose \ | ||
--local_dir build \ | ||
--fqdn webcenter-text-export-dev.manuele-vaccari.ch | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
# Builder instance (see setup-buildx action) | ||
# builder: | ||
# Build's context is the set of files located in the specified PATH or URL | ||
# context: . # default is "<Git context>" | ||
# Path to the Dockerfile | ||
# file: ./Dockerfile # default is "Dockerfile" | ||
# List of build-time variables | ||
# build-args: # optional | ||
# List of metadata for an image | ||
# https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||
labels: | # optional | ||
maintainer=Manuele Vaccari <[email protected]> | ||
org.opencontainers.image.created=${{ steps.prep.outputs.created }} | ||
org.opencontainers.image.url=${{ github.event.repository.html_url }} | ||
org.opencontainers.image.source=${{ github.event.repository.clone_url }} | ||
org.opencontainers.image.version=${{ steps.prep.outputs.version }} | ||
org.opencontainers.image.revision=${{ github.sha }} | ||
org.opencontainers.image.title=${{ github.event.repository.name }} | ||
org.opencontainers.image.description=${{ github.event.repository.description }} | ||
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }} | ||
# List of tags | ||
tags: ${{ steps.prep.outputs.tags }} | ||
# Always attempt to pull a newer version of the image | ||
# pull: false # optional, default is "false" | ||
# Sets the target stage to build | ||
# target: # optional | ||
# List of extra privileged entitlement (eg. network.host,security.insecure) | ||
# allow: # optional | ||
# Do not use cache when building the image | ||
# no-cache: false # optional, default is "false" | ||
# List of target platforms for build | ||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6 # optional | ||
# Load is a shorthand for --output=type=docker | ||
# load: false # optional, default is "false" | ||
# Push is a shorthand for --output=type=registry | ||
push: ${{ github.event_name != 'pull_request' }} # optional, default is "false" | ||
# List of output destinations (format: type=local,dest=path) | ||
# outputs: # optional | ||
# List of external cache sources (eg. type=local,src=path/to/dir) | ||
cache-from: type=local,src=/tmp/.buildx-cache # optional | ||
# List of cache export destinations (eg. type=local,dest=path/to/dir) | ||
cache-to: type=local,dest=/tmp/.buildx-cache # optional | ||
# List of secrets to expose to the build (eg. key=value, GIT_AUTH_TOKEN=mytoken) | ||
# secrets: # optional |
Oops, something went wrong.