Skip to content

Commit 24107f5

Browse files
authored
Merge pull request #5 from mhitza/container-changes
Tweaks for devcontainer and GitHub actions changes
2 parents 9b915b2 + 2b8ff74 commit 24107f5

5 files changed

Lines changed: 84 additions & 34 deletions

File tree

.github/workflows/production.yml

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- cron: 00 4 * * *
1010

1111
jobs:
12-
ghcr:
12+
php7:
1313
runs-on: ubuntu-latest
1414

1515
steps:
@@ -44,49 +44,81 @@ jobs:
4444
severity: 'CRITICAL,HIGH'
4545

4646
- name: Retag new image with latest tag so we can push the scanned version
47-
run: docker image tag php-docker-base:trivytemp ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:latest
47+
run: docker image tag php-docker-base:trivytemp ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:latest
4848

4949
- name: Push with latest tag
50-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:latest
50+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:latest
5151
- name: Retag new image with commit hash
52-
run: docker image tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:latest ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:$(echo ${GITHUB_SHA} | cut -c1-8)
52+
run: docker image tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:latest ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:$(echo ${GITHUB_SHA} | cut -c1-8)
5353
- name: Push with commit hash tag
54-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:$(echo ${GITHUB_SHA} | cut -c1-8)
54+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:$(echo ${GITHUB_SHA} | cut -c1-8)
5555
- name: Retag new image with php7 tag
56-
run: docker image tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:latest ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php7
56+
run: docker image tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:latest ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php7
5757
- name: Push with commit php7 tag
58-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php7
58+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php7
5959

6060
#php7-review
6161
- name: Build the PHP7 review container image
62-
run: docker build . --tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php7-review --file Dockerfile.php7-review
62+
run: docker build . --tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php7-review --file Dockerfile.php7-review
6363
- name: Push with commit php7-review tag
64-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php7-review
64+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php7-review
65+
66+
php8:
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: GitHub Environment Variables Action
70+
uses: FranzDiebold/github-env-vars-action@v2
71+
72+
- name: Shallow clone code
73+
uses: actions/checkout@v3
74+
with:
75+
fetch-depth: 0
76+
77+
- name: Login to Container Registry ghcr.io
78+
uses: docker/login-action@v2
79+
with:
80+
registry: ghcr.io
81+
username: ${{ github.actor }}
82+
password: ${{ secrets.GITHUB_TOKEN }}
6583

6684
#php8
6785
- name: Build the container image
68-
run: docker build . --tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8 --file Dockerfile.php8
86+
run: docker build . --tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8 --file Dockerfile.php8
6987
- name: Run Trivy vulnerability scanner
7088
uses: aquasecurity/trivy-action@master
7189
with:
72-
image-ref: ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8
90+
image-ref: ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8
7391
format: 'table'
7492
exit-code: '1'
7593
ignore-unfixed: true
7694
vuln-type: 'os,library'
7795
severity: 'CRITICAL,HIGH'
7896
- name: Push with php8 tag
79-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8
97+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8
8098
- name: Retag new image with commit hash
81-
run: docker image tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8 ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8-$(echo ${GITHUB_SHA} | cut -c1-8)
99+
run: docker image tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8 ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8-$(echo ${GITHUB_SHA} | cut -c1-8)
82100
- name: Push with commit hash tag and php8 tag
83-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8-$(echo ${GITHUB_SHA} | cut -c1-8)
101+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8-$(echo ${GITHUB_SHA} | cut -c1-8)
84102

85103
#php8-review
86104
- name: Build the PHP8 review container image
87-
run: docker build . --tag ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8-review --file Dockerfile.php8-review
105+
run: docker build . --tag ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8-review --file Dockerfile.php8-review
88106
- name: Push with commit php8-review tag
89-
run: docker push ghcr.io/linkorb/${{ env.CI_REPOSITORY_NAME }}:php8-review
107+
run: docker push ghcr.io/${{ github.repository_owner }}/${{ env.CI_REPOSITORY_NAME }}:php8-review
108+
109+
cleanup:
110+
needs: [php7, php8]
111+
runs-on: ubuntu-latest
112+
steps:
113+
- name: GitHub Environment Variables Action
114+
uses: FranzDiebold/github-env-vars-action@v2
115+
116+
- name: Login to Container Registry ghcr.io
117+
uses: docker/login-action@v2
118+
with:
119+
registry: ghcr.io
120+
username: ${{ github.actor }}
121+
password: ${{ secrets.GITHUB_TOKEN }}
90122

91123
- name: Delete old versions of the package, keeping a few of the newest
92124
uses: actions/delete-package-versions@v4

Dockerfile.php7

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ RUN apt-get update \
3232
unzip \
3333
vim \
3434
zip \
35+
ca-certificates \
36+
gnupg \
3537
&& apt-get autoremove \
3638
&& apt-get clean \
3739
&& rm -rf /var/lib/apt/lists/*
3840

3941

40-
RUN curl https://deb.nodesource.com/setup_18.x -o install_node.sh \
41-
&& chmod +x install_node.sh \
42-
&& ./install_node.sh \
43-
&& apt install -y nodejs make \
44-
&& apt-get autoremove \
45-
&& apt-get clean \
46-
&& rm -rf /var/lib/apt/lists/*
42+
# Based on nodesource installation instructions https://github.com/nodesource/distributions#installation-instructions
43+
RUN mkdir -p /etc/apt/keyrings \
44+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
45+
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
46+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
47+
&& apt-get update \
48+
&& apt-get install nodejs -y
4749

4850
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg \
4951
| gpg --dearmor >> /usr/share/keyrings/yarnkey.gpg \

Dockerfile.php7-review

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN mkdir -p /opt
55

66
WORKDIR /opt/
77

8+
# Do not run Composer as root/super user! See https://getcomposer.org/root for details
9+
# Aborting as no plugin should be loaded if running as super user is not explicitly allowed
10+
ENV COMPOSER_ALLOW_SUPERUSER=1
11+
812
# install php-tools
913
RUN git clone https://github.com/linkorb/php-tools.git
1014
RUN cd php-tools && COMPOSER_MEMORY_LIMIT=-1 /usr/bin/composer install
@@ -13,7 +17,7 @@ RUN cd php-tools && COMPOSER_MEMORY_LIMIT=-1 /usr/bin/composer install
1317
RUN curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s
1418
RUN mv /opt/bin/reviewdog /usr/local/bin
1519

16-
# add php-tools to search path
17-
RUN echo "export PATH=$PATH:/opt/php-tools/bin" >> /root/.bashrc
20+
# add php-tools to search path globally
21+
RUN echo "export PATH=$PATH:/opt/php-tools/bin" >> /etc/bash.bashrc
1822

1923
ENTRYPOINT ["apache2-foreground"]

Dockerfile.php8

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,20 @@ RUN apt-get update \
3232
unzip \
3333
vim \
3434
zip \
35+
ca-certificates \
36+
gnupg \
3537
&& apt-get autoremove \
3638
&& apt-get clean \
3739
&& rm -rf /var/lib/apt/lists/*
3840

3941

40-
RUN curl https://deb.nodesource.com/setup_18.x -o install_node.sh \
41-
&& chmod +x install_node.sh \
42-
&& ./install_node.sh \
43-
&& apt install -y nodejs make \
44-
&& apt-get autoremove \
45-
&& apt-get clean \
46-
&& rm -rf /var/lib/apt/lists/*
42+
# Based on nodesource installation instructions https://github.com/nodesource/distributions#installation-instructions
43+
RUN mkdir -p /etc/apt/keyrings \
44+
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key \
45+
| gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
46+
&& echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_18.x nodistro main" > /etc/apt/sources.list.d/nodesource.list \
47+
&& apt-get update \
48+
&& apt-get install nodejs -y
4749

4850
RUN curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg \
4951
| gpg --dearmor >> /usr/share/keyrings/yarnkey.gpg \

Dockerfile.php8-review

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ RUN mkdir -p /opt
55

66
WORKDIR /opt/
77

8+
# Do not run Composer as root/super user! See https://getcomposer.org/root for details
9+
# Aborting as no plugin should be loaded if running as super user is not explicitly allowed
10+
ENV COMPOSER_ALLOW_SUPERUSER=1
11+
812
# install php-tools
913
RUN git clone https://github.com/linkorb/php-tools.git
1014
RUN cd php-tools && COMPOSER_MEMORY_LIMIT=-1 /usr/bin/composer install
@@ -13,10 +17,16 @@ RUN cd php-tools && COMPOSER_MEMORY_LIMIT=-1 /usr/bin/composer install
1317
RUN curl -sfL https://raw.githubusercontent.com/reviewdog/reviewdog/master/install.sh | sh -s
1418
RUN mv /opt/bin/reviewdog /usr/local/bin
1519

16-
# add php-tools to search path
17-
RUN echo "export PATH=$PATH:/opt/php-tools/bin" >> /root/.bashrc
20+
# add php-tools to search path globally
21+
RUN echo "export PATH=$PATH:/opt/php-tools/bin" >> /etc/bash.bashrc
1822

1923
RUN composer global require icanhazstring/composer-unused \
2024
&& ln -s /root/.config/composer/vendor/bin/composer-unused /usr/local/bin/composer-unused
2125

26+
RUN apt-get update && apt-get install -y python3-pip && python3 -m pip install yamllint --break-system-packages
27+
28+
# Caused the appearance of a git untracked index.html file within the GitHub codespace (when image used as
29+
# the base of a devcontainer)
30+
RUN rm /app/index.html
31+
2232
ENTRYPOINT ["apache2-foreground"]

0 commit comments

Comments
 (0)