Update php version with Dockerfile

Hi everyone,

I’m facing some issues with my Docker image that I’m using as Github action runner. I’m using the Docker image from https://github.com/myoung34/docker-github-actions-runner as a base and then running a series of commands.

My Dockerfile:

# base
FROM myoung34/github-runner:latest

# Let's create a nice FAT image with all bells & whistles
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - \
    && \
    apt-key adv --fetch-keys https://dl.yarnpkg.com/debian/pubkey.gpg \
    && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list \
    && \
    add-apt-repository -y ppa:apt-fast/stable \
    && \
    apt-get update \
    && \ 
    apt install -y --no-install-recommends \
    vim \
    apt-utils \
    apt-fast \
    rsync \
    gcc \
    g++ \
    make \
    dh-autoreconf \
    zip \
    php-cli \
    php-curl \
    php-xml \
    php-zip \
    php-mbstring \
    python \
    unzip \
    nodejs \
    yarn \
    phantomjs \
    && \
    apt clean \
    && \
    curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer \
    && \
    npm i -g gulp \
    && \
    mkdir -p /actions-runner/installers

WORKDIR /actions-runner

COPY ./installers /actions-runner/installers
COPY ./ssh /actions-runner/ssh

RUN chmod +x /actions-runner/installers/ssh-keys.sh \
  && chmod +x /actions-runner/installers/google-chrome.sh \
  && /actions-runner/installers/ssh-keys.sh \
  && /actions-runner/installers/google-chrome.sh \
  && rm -rf /actions-runner/installers \
  && rm -rf /actions-runner/ssh \ 
  && rm -rf /var/lib/apt/lists/* \
  && rm -rf /tmp/*

ENV QT_QPA_PLATFORM=offscreen
RUN echo 'alias gsed="sed"' >> ~/.bashrc
RUN echo -e '#!/bin/bash\nsed "$@"' > /usr/bin/gsed && \
    chmod +x /usr/bin/gsed

I’m struggling to upgrade the PHP version in the Dockerfile. I’ve seen some examples using FROM php:8.1-fpm in the Dockerfile. However, since I’m already using FROM myoung34/github-runner:latest, I’m unsure how to combine these.

Any assistance or guidance would be greatly appreciated.

While at it, you should also update Node

Node.js 12 will reach End-of-Life status on 30 April 2022

Can’t you spin up a separate container for PHP from the github-runner?

Thanks for the reply.

I’m not sure how to do that, because I can only apply 1 Dockerfile to the worker right?
My docker-compose.yml:

version: '3.4'

services:
  worker:
    build: .
    environment: 
      RUNNER_WORKDIR: /tmp/runner/work
      RUNNER_NAME_PREFIX: sam
      ORG_NAME: Emotion-nl
      RUNNER_SCOPE: org
      LABELS: node12,sam
      ACCESS_TOKEN: ghp_***************************************
      DISABLE_AUTO_UPDATE: "true"
      TZ: Europe/Amsterdam
    restart: always
    volumes:
      - '/var/run/docker.sock:/var/run/docker.sock'

I resolved it by using the package ppa:ondrej/php . For those facing the same issue, my Dockerfile now looks like this:

# base
FROM myoung34/github-runner:latest

# Let's create a nice FAT image with all bells & whistles
RUN add-apt-repository -y ppa:ondrej/php && \
    add-apt-repository -y ppa:apt-fast/stable && \
    curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
    apt-key adv --fetch-keys https://dl.yarnpkg.com/debian/pubkey.gpg && \
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list \
    && \
    apt-get update \
    && \
    apt install -y --no-install-recommends \
    vim \
    apt-utils \
    apt-fast \
    rsync \
    gcc \
    g++ \
    make \
    dh-autoreconf \
    zip \
    php8.1-cli \
    php8.1-curl \
    php8.1-xml \
    php8.1-zip \
    php8.1-mbstring \
    php8.1-bcmath \
    php8.1-intl \
    python \
    unzip \
    nodejs \
    yarn \
    phantomjs \
    && \
    apt clean \
    && \
    npm i -g gulp \
    && \
    mkdir -p /actions-runner/installers

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin/ --filename=composer

WORKDIR /actions-runner

COPY ./installers /actions-runner/installers
COPY ./ssh /actions-runner/ssh

RUN chmod +x /actions-runner/installers/ssh-keys.sh \
  && chmod +x /actions-runner/installers/google-chrome.sh \
  && /actions-runner/installers/ssh-keys.sh \
  && /actions-runner/installers/google-chrome.sh \
  && rm -rf /actions-runner/installers \
  && rm -rf /actions-runner/ssh \ 
  && rm -rf /var/lib/apt/lists/* \
  && rm -rf /tmp/*

ENV QT_QPA_PLATFORM=offscreen
RUN echo 'alias gsed="sed"' >> ~/.bashrc
RUN echo -e '#!/bin/bash\nsed "$@"' > /usr/bin/gsed && \
    chmod +x /usr/bin/gsed

With ppa:ondrej/php , I have access to the latest PHP version. In the RUN command, I can specify the PHP version to be used, as you can see in my code.