-
Notifications
You must be signed in to change notification settings - Fork 8
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
2 changed files
with
86 additions
and
45 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,59 @@ | ||
name: Release image for local development environment | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
- develop | ||
- docker_support | ||
|
||
env: | ||
IMAGE_NAME: ${{ github.repository }}/${{ github.event.repository.name }} | ||
|
||
jobs: | ||
build: | ||
name: Automated release fo Docker image | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: nelonoel/branch-name@v1.0.1 | ||
|
||
- name: Build and tag the image for testing and release | ||
run: >- | ||
docker build . | ||
--file Dockerfile | ||
--tag docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | ||
- name: Set release tag | ||
# https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable | ||
run: echo "RELEASE_VERSION=$(printf -- '%s%s\n' $(cat .release-version) $([ ${BRANCH_NAME} = "develop" ] && printf -- '-%s-develop' ${GITHUB_RUN_ID} || echo ""))" >> $GITHUB_ENV | ||
|
||
- name: Login to registry | ||
run: >- | ||
docker login | ||
-u ${{ github.actor }} | ||
-p ${{ secrets.GITHUB_TOKEN }} | ||
docker.pkg.github.com | ||
- name: Tag image with release version | ||
run: >- | ||
docker tag | ||
docker.pkg.github.com/${IMAGE_NAME}:${BRANCH_NAME} | ||
docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_VERSION }} | ||
- name: Push release tag image to registry | ||
run: >- | ||
docker push docker.pkg.github.com/${IMAGE_NAME}:${{ env.RELEASE_VERSION }} | ||
- name: Remove old releases | ||
uses: snok/container-retention-policy@v2 | ||
with: | ||
image-names: ${{ github.event.repository.name }}/* | ||
cut-off: Four months ago UTC | ||
timestamp-to-use: updated_at | ||
account-type: org | ||
org-name: sanger | ||
keep-at-least: 5 | ||
skip-tags: latest | ||
token: ${{ secrets.REMOVE_OLD_IMAGES }} |
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,55 +1,37 @@ | ||
FROM ruby:2.7.5-slim | ||
ARG CHIPSET=default | ||
|
||
# Use the correct base image depending on the architecture | ||
# For Apple M1 Chip, run: docker build --build-arg CHIPSET=m1 | ||
FROM ruby:2.7.8-slim AS base_default | ||
FROM --platform=linux/amd64 ruby:2.7.8-slim AS base_m1 | ||
FROM base_${CHIPSET} AS base | ||
|
||
ARG bundlerWithout="development test lint" | ||
ARG yarnFlags="--production" | ||
|
||
# Install required software: | ||
# - net-tools: to run ping and other networking tools | ||
# - build-essential: to have a compiling environment for building gems | ||
# - curl: for setting Node version and healthcheck | ||
# - git is a rails gems dependency | ||
RUN apt-get update | ||
RUN apt-get install -y build-essential | ||
RUN apt-get install -y curl | ||
RUN apt-get install -y git | ||
|
||
# Set Node to install version 14 | ||
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - | ||
RUN apt-get update | ||
RUN apt-get install -y nodejs | ||
# - curl: for healthcheck | ||
# - yarn and git are rails gems dependencies | ||
RUN apt-get update && apt-get install -y \ | ||
build-essential \ | ||
curl \ | ||
git \ | ||
net-tools \ | ||
nodejs \ | ||
npm \ | ||
vim \ | ||
wget \ | ||
yarn | ||
|
||
# Change the working directory for all proceeding operations | ||
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#workdir | ||
WORKDIR /code | ||
|
||
# Install build tools | ||
COPY Gemfile /code | ||
COPY Gemfile.lock /code | ||
|
||
ADD . /code/ | ||
|
||
# Rails installation | ||
RUN npm install --global yarn | ||
RUN gem install bundler | ||
|
||
# Install bundler based dependencies | ||
COPY Gemfile . | ||
COPY Gemfile.lock . | ||
RUN bundle config set without "${bundlerWithout}" | ||
RUN bundle install | ||
|
||
# Install yarn based dependencies | ||
COPY package.json . | ||
COPY yarn.lock . | ||
RUN rm -rf node_modules && yarn install --frozen-lockfile ${yarnFlags} | ||
|
||
# "items (files, directories) that do not require ADD’s tar auto-extraction capability, you should always use COPY." | ||
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy | ||
COPY . . | ||
|
||
# Set up ENTRYPOINT script as a system binary | ||
COPY entrypoint.sh /usr/bin/ | ||
RUN chmod +x /usr/bin/entrypoint.sh | ||
|
||
# "The best use for ENTRYPOINT is to set the image’s main command, allowing that image to be run as though it was that | ||
# command (and then use CMD as the default flags)." | ||
# https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint | ||
ENTRYPOINT ["entrypoint.sh"] | ||
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0", "-p", "3001"] | ||
|
||
# https://docs.docker.com/engine/reference/builder/#healthcheck | ||
HEALTHCHECK --interval=30s --timeout=10s --retries=4 \ | ||
CMD curl -f http://localhost:3001/health || exit 1 | ||
RUN yarn --install |