Skip to content

Commit 073695d

Browse files
authored
Upgrades (#51)
increment ubuntu container version move from pygithub to ghapi skip the chown step
1 parent f632b80 commit 073695d

File tree

7 files changed

+50
-56
lines changed

7 files changed

+50
-56
lines changed

Dockerfile

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:20.04 AS codeql_base
1+
FROM ubuntu:22.04 AS codeql_base
22
LABEL maintainer="Github codeql team"
33

44
# tzdata install needs to be non-interactive
@@ -12,33 +12,31 @@ RUN adduser --home ${CODEQL_HOME} ${USERNAME} && \
1212
apt-get update && \
1313
apt-get upgrade -y && \
1414
apt-get install -y --no-install-recommends \
15-
software-properties-common \
16-
nodejs \
17-
vim \
18-
curl \
19-
wget \
20-
git \
21-
build-essential \
22-
unzip \
23-
apt-transport-https \
24-
python3.8 \
25-
python3-venv \
26-
python3-pip \
27-
python3-setuptools \
28-
python3-dev \
29-
gnupg \
30-
g++ \
31-
make \
32-
gcc \
33-
apt-utils \
34-
rsync \
35-
file \
36-
dos2unix \
37-
gettext && \
38-
apt-get clean && \
39-
rm -f /usr/bin/python /usr/bin/pip && \
40-
ln -s /usr/bin/python3.8 /usr/bin/python && \
41-
ln -s /usr/bin/pip3 /usr/bin/pip
15+
software-properties-common \
16+
nodejs \
17+
vim \
18+
curl \
19+
wget \
20+
git \
21+
build-essential \
22+
unzip \
23+
apt-transport-https \
24+
python3.10 \
25+
python3-venv \
26+
python3-pip \
27+
python3-setuptools \
28+
python3-dev \
29+
python-is-python3 \
30+
gnupg \
31+
g++ \
32+
make \
33+
gcc \
34+
apt-utils \
35+
rsync \
36+
file \
37+
dos2unix \
38+
gettext && \
39+
apt-get clean
4240

4341
# Install .NET Core and Java for tools/builds
4442
RUN cd /tmp && \
@@ -48,15 +46,13 @@ RUN cd /tmp && \
4846
apt-get install -y default-jdk apt-transport-https && \
4947
apt-get update && \
5048
rm packages-microsoft-prod.deb
51-
RUN apt-get install -y dotnet-sdk-3.1
49+
RUN apt-get install -y dotnet-sdk-6.0
5250

5351
# Clone our setup and run scripts
54-
#RUN git clone https://github.com/microsoft/codeql-container /usr/local/startup_scripts
5552
RUN mkdir -p /usr/local/startup_scripts
56-
RUN ls -al /usr/local/startup_scripts
5753
COPY container /usr/local/startup_scripts/
58-
RUN pip3 install --upgrade pip \
59-
&& pip3 install -r /usr/local/startup_scripts/requirements.txt
54+
55+
RUN pip3 install -r /usr/local/startup_scripts/requirements.txt
6056

6157
# Install latest codeQL
6258

@@ -83,8 +79,8 @@ RUN codeql query compile --threads=0 ${CODEQL_HOME}/codeql-repo/*/ql/src/codeql-
8379
ENV PYTHONIOENCODING=utf-8
8480

8581
# Change ownership of all files and directories within CODEQL_HOME to the codeql user
86-
RUN chown -R ${USERNAME}:${USERNAME} ${CODEQL_HOME}
82+
#RUN chown -R ${USERNAME}:${USERNAME} ${CODEQL_HOME}
8783

8884
USER ${USERNAME}
8985

90-
ENTRYPOINT ["python3", "/usr/local/startup_scripts/startup.py"]
86+
ENTRYPOINT ["python3", "/usr/local/startup_scripts/startup.py"]
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/usr/bin/env python3
22
# get the parent directory of the script, to link libs
3-
4-
import os
5-
import sys
6-
73
from libs.github import get_latest_github_repo_version
84

95
def main():
10-
latest_release = get_latest_github_repo_version("github/codeql-cli-binaries")
11-
print(latest_release.title)
6+
latest_release = get_latest_github_repo_version("github", "codeql-cli-binaries")
7+
print(latest_release.tag_name)
128

139
main()

container/libs/codeql.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ def download_and_install_latest_codeql(self, github_version):
3434
download_url = None
3535
download_path = None
3636
if os_name == 'posix':
37-
download_url = f'{self.CODEQL_GITHUB_URL}/releases/download/{github_version.title}/codeql-linux64.zip'
37+
download_url = f'{self.CODEQL_GITHUB_URL}/releases/download/{github_version.tag_name}/codeql-linux64.zip'
3838
download_path = f'{self.TEMP_DIR}/codeql_linux.zip'
3939
elif os_name == 'nt':
40-
download_url = f'{self.CODEQL_GITHUB_URL}/releases/download/{github_version.title}/codeql-win64.zip'
40+
download_url = f'{self.CODEQL_GITHUB_URL}/releases/download/{github_version.tag_name}/codeql-win64.zip'
4141
download_path = f'{self.TEMP_DIR}/codeql_windows.zip'
4242
else:
4343
exit(self.ERROR_UNKNOWN_OS)
4444

45-
logger.info(f'Downloading codeql-cli version {github_version.title}...')
45+
logger.info(f'Downloading codeql-cli version {github_version.tag_name}...')
4646
check_output_wrapper(f"wget -q {download_url} -O {download_path}", shell=True).decode("utf-8")
4747
self.install_codeql_cli(download_path)
4848
#rm /tmp/codeql_linux.zip
@@ -77,7 +77,7 @@ def get_current_local_version(self):
7777
return version
7878

7979
def get_latest_codeql_github_version(self):
80-
return get_latest_github_repo_version("github/codeql-cli-binaries")
80+
return get_latest_github_repo_version("github", "codeql-cli-binaries")
8181

8282
def install_codeql_cli(self, download_path):
8383
logger.info("Installing codeql-cli...")

container/libs/github.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import os
22
from datetime import datetime, MINYEAR
3-
from github import Github, GitRelease, Repository, GithubException
3+
from ghapi.all import GhApi
4+
from datetime import datetime, timezone
5+
from dateutil import parser
46

5-
def get_latest_github_repo_version(repo):
7+
def get_latest_github_repo_version(owner, repository):
68
# check for a github token that may be used alongside the codeql cli to upload github results
79
# this will limit rate limting 403 errors on checking codeql versions, as the request will be authenticated if possible.
810
# by default codeql uses env var "GITHUB_TOKEN" to authenticate
911
# https://codeql.github.com/docs/codeql-cli/manual/github-upload-results/
1012
access_token = os.getenv('GITHUB_TOKEN')
11-
client = Github(access_token) if access_token != None else Github()
12-
repo = client.get_repo(repo)
13-
releases = repo.get_releases()
13+
api = GhApi(owner=owner, repo=repository, token=access_token) if access_token != None else GhApi(owner=owner, repo=repository)
14+
releases = api.repos.list_releases()
1415
latest_release = get_latest_github_release(releases)
1516
return latest_release
1617

1718
def get_latest_github_release(releases):
1819
latest_release = None
19-
latest_date = datetime(MINYEAR, 1, 1)
20+
latest_date = datetime(MINYEAR, 1, 1).replace(tzinfo=timezone.utc)
2021
for release in releases:
21-
if release.created_at > latest_date:
22-
latest_date = release.created_at
22+
release_date = parser.parse(release.created_at)
23+
if release_date > latest_date:
24+
latest_date = release_date
2325
latest_release = release
2426
return latest_release

container/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
PyGithub==1.43.7
1+
ghapi==1.0.3
2+
python-dateutil==2.8.2

container/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def get_latest_codeql(args):
4646
# ensure we only query for the latest codeql cli version if we might actually update it
4747
if args.check_latest_cli:
4848
latest_online_version = codeql.get_latest_codeql_github_version()
49-
if current_installed_version != latest_online_version.title:
49+
if current_installed_version != latest_online_version.tag_name:
5050
# we got a newer version online, download and install it
5151
codeql.download_and_install_latest_codeql(latest_online_version)
5252
# get the latest queries regardless (TODO: Optimize by storing and checking the last commit hash?)

container/startup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env python3
22
import os
3-
import sys
43
from time import sleep
54
from libs.utils import get_env_variable, check_output_wrapper, get_logger
65
from libs.codeql import *

0 commit comments

Comments
 (0)