Skip to content

Commit cd42967

Browse files
authored
Merge pull request iiab#4176 from Ark74/fix_code_latest
[code] work around non-interactive curl/ansible requests get 403
2 parents 29e220c + 55f1253 commit cd42967

File tree

8 files changed

+130
-56
lines changed

8 files changed

+130
-56
lines changed

.github/workflows/tests/expected_state_medium.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ awstats_installed: True
2424
matomo_installed: True
2525
captiveportal_installed: True
2626
calibreweb_installed: True
27-
code_installed: True

roles/code/defaults/main.yml

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# Initial COTG role to setup distribution site
2-
# 64bits support, leaving room for future 32bits support.
3-
4-
# URL apk download urls
5-
adfa_code_download_url: https://appdevforall.org/apk_repo
6-
code_apk_release_name: "CodeOnTheGo-latest.apk"
7-
8-
## Set arch for future releases
9-
#code_apk_release_arch64: ""
10-
#code_apk_release_arch32: ""
11-
12-
# Last build site
1+
# Initial "Code on the Go" role to set up "offline" distribution.
2+
# 64-bit support for now, leaving room for future 32-bit support.
3+
4+
# URL & Regular Expressions
5+
code_download_url: https://appdevforall.org/apk_repo
6+
code_apk_32bit_pattern: "CodeOnTheGo-.*?armv7a\\.apk"
7+
code_apk_64bit_pattern: "CodeOnTheGo-.*?armv8a\\.apk"
8+
9+
# 2025-12-13: Filename vars had been dynamically bound to non-existent
10+
# (undefined) vars, auto-populated after scraping above URL, but let's not!
11+
# Cleaner: install.yml now sets these 2 vars, after scraping the above URL...
12+
#
13+
# code_apk_32bit_filename:
14+
# code_apk_64bit_filename:
15+
16+
# Date Scraped
1317
code_play_build_date: "{{ lookup('pipe', 'date -R') }}"
1418

1519
# Root folder path vars
@@ -19,15 +23,3 @@ code_data_root: "{{ content_base }}/code" # /library/code
1923
code_data_root_static: "{{ code_serve_path }}/static"
2024
code_data_root_apk: "{{ code_data_root_static }}/apk"
2125
code_data_root_content: "{{ code_data_root_static }}/content"
22-
23-
code_arm64_release_apk:
24-
- name: "{{ code_apk_release_name }}"
25-
filename: "{{ code_apk_release_name }}"
26-
sha256sum: "28022d3ad8e288ab8d9a9b7067a278bacb4788cf41098fc580e5a94538bc75f8"
27-
28-
## future releases might include
29-
#code_arm32_release_apk:
30-
# - name: "{{ code_apk_release_name }}"
31-
# filename: "{{ code_apk_release_name }}"
32-
# sha256sum: ""
33-
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
- name: Enable http://box/code via NGINX, by installing {{ nginx_conf_dir }}/code-nginx.conf
2-
ansible.builtin.copy:
2+
copy:
33
src: code-nginx.conf
44
dest: "{{ nginx_conf_dir }}/code-nginx.conf" # /etc/nginx/conf.d
55
mode: "0644"
66
when: code_enabled
77

88
- name: Disable http://box/code via NGINX, by removing {{ nginx_conf_dir }}/code-nginx.conf
9-
ansible.builtin.file:
9+
file:
1010
path: "{{ nginx_conf_dir }}/code-nginx.conf" # /etc/nginx/conf.d
1111
state: absent
1212
when: not code_enabled

roles/code/tasks/install.yml

Lines changed: 89 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
- name: Make code directories available
7-
ansible.builtin.file:
7+
file:
88
path: "{{ item }}"
99
state: directory
1010
mode: "0755"
@@ -13,39 +13,116 @@
1313
- "{{ code_serve_path }}"
1414

1515
- name: Copy static assets
16-
ansible.builtin.copy:
16+
copy:
1717
src: static/
1818
dest: "{{ code_data_root_static }}"
1919

20+
- name: Ensure code_apk_release_name is set (autodetect latest armv8a APK if empty)
21+
when: code_apk_release_name is undefined
22+
block:
23+
24+
- name: Fetch APK index page from {{ code_download_url }}/
25+
uri:
26+
url: "{{ code_download_url }}/"
27+
return_content: true
28+
register: apk_index
29+
failed_when: apk_index.status != 200 and apk_index.status != 403
30+
31+
- name: Mark 'code' role as blocked by CDN
32+
set_fact:
33+
code_blocked_by_cdn: true
34+
when: apk_index.status == 403
35+
36+
- name: Warn about 403 APK index
37+
fail:
38+
msg: |
39+
The 'code' role could not access: {{ code_download_url }}/ (HTTP 403). CDN is likely blocking datacenter IPs.
40+
41+
================ CODE ROLE WARNING ================
42+
The 'code' role hit a CDN 403 (APK index query blocked).
43+
44+
HTTP status: 403
45+
This likely means the APK store is behind some CDN and
46+
blocking datacenter IP ranges, so non-interactive curl/Ansible
47+
requests get a 403 "Just a moment..." page.
48+
49+
GitHub issues/PRs related:
50+
- https://github.com/iiab/iiab/issues/4174
51+
- https://github.com/iiab/iiab/pull/4176
52+
53+
Continuing IIAB without CodeOnTheGo APK content...
54+
===================================================
55+
when: code_blocked_by_cdn is defined
56+
ignore_errors: yes
57+
58+
- name: Warn about APK index 403 blocking
59+
pause:
60+
seconds: 20
61+
when: code_blocked_by_cdn is defined
62+
63+
- name: Extract latest armv8a APK filename from index
64+
set_fact:
65+
code_apk_64bit_filename: >-
66+
{{
67+
apk_index.content
68+
| regex_findall(code_apk_64bit_pattern)
69+
| sort
70+
| last
71+
}}
72+
when: code_blocked_by_cdn is undefined
73+
74+
- name: Extract latest armv7a APK filename from index
75+
set_fact:
76+
code_apk_32bit_filename: >-
77+
{{
78+
apk_index.content
79+
| regex_findall(code_apk_32bit_pattern)
80+
| sort
81+
| last
82+
}}
83+
when: code_blocked_by_cdn is undefined
84+
2085
- name: Get CodeOnTheGo version number
21-
ansible.builtin.shell: >
22-
curl -s https://appdevforall.org/apk_repo/ |
23-
sed -nE 's/.*CodeOnTheGo-release([0-9.]+)\.apk.*/\1/p'
24-
register: cotg_version_raw
25-
changed_when: false
86+
set_fact:
87+
cotg_version: "{{ code_apk_64bit_filename | regex_search('CodeOnTheGo-release([0-9.]+)', '\\1') }}"
88+
when: code_blocked_by_cdn is undefined
89+
90+
- name: "Show resolved APK release name"
91+
debug:
92+
var: cotg_version
93+
when: code_blocked_by_cdn is undefined
2694

2795
- name: Make index.html file
28-
ansible.builtin.template:
96+
template:
2997
src: "index.html.j2"
3098
dest: "{{ code_serve_path }}/index.html"
3199
mode: "0644"
100+
when: code_blocked_by_cdn is undefined
32101

33102
- name: Make content directory
34103
file:
35104
path: "{{ code_data_root_content }}"
36105
state: directory
37106
mode: "0755"
107+
when: code_blocked_by_cdn is undefined
38108

39109
- name: Render localized Markdown content files
40-
ansible.builtin.template:
110+
template:
41111
src: "content/{{ item }}.md.j2"
42112
dest: "{{ code_data_root_content }}/{{ item }}.md"
43113
mode: "0644"
44114
loop:
45115
- en
46116
- es
117+
when: code_blocked_by_cdn is undefined
118+
119+
- name: Continue APK install tasks when no 403 blocking
120+
include_tasks: install_apkfile.yml
121+
when: code_blocked_by_cdn is undefined
47122

48-
- include_tasks: install_apkfile.yml
123+
- name: Setup 'code' nginx conf file
124+
include_tasks: nginx.yml
125+
when: code_blocked_by_cdn is undefined
49126

50127

51128
# RECORD CODE AS INSTALLED
@@ -64,9 +141,11 @@
64141
- name: "Set 'code_installed: True'"
65142
set_fact:
66143
code_installed: True
144+
when: code_blocked_by_cdn is undefined
67145

68146
- name: "Add 'code_installed: True' to {{ iiab_state_file }}"
69147
lineinfile:
70148
path: "{{ iiab_state_file }}" # /etc/iiab/iiab_state.yml
71149
regexp: '^code_installed'
72150
line: 'code_installed: True'
151+
when: code_blocked_by_cdn is undefined

roles/code/tasks/install_apkfile.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@
55
# mode: 0755
66

77
### Current release - arm64 ###
8-
- name: Download arch arm64 APK
9-
ansible.builtin.get_url:
10-
url: "{{ adfa_code_download_url }}/{{ item.filename }}"
11-
dest: "{{ code_data_root_apk }}/{{ item.filename }}"
12-
#checksum: "sha256:{{ item.sha256sum }}"
8+
- name: Download arch arm 64-bits APK
9+
get_url:
10+
url: "{{ code_download_url }}/{{ code_apk_64bit_filename }}"
11+
dest: "{{ code_data_root_apk }}/{{ code_apk_64bit_filename }}"
1312
mode: "0644"
1413
timeout: "{{ download_timeout }}"
15-
loop: "{{ code_arm64_release_apk }}"
16-
14+
1715
### Future release - arm32 ###
18-
#- name: Download arch arm32 apk (0644)
19-
# ansible.builtin.get_url:
20-
# url: "{{ adfa_code_download_url }}/{{ item.filename }}"
21-
# dest: "{{ code_data_root_apk }}/{{ item.filename }}"
22-
# checksum: "sha256:{{ item.sha256sum }}"
16+
#- name: Download arch arm 32-bits APK
17+
# get_url:
18+
# url: "{{ code_download_url }}/{{ code_apk_32bit_filename }}"
19+
# dest: "{{ code_data_root_apk }}/{{ code_apk_32bit_filename }}"
2320
# mode: "0644"
2421
# timeout: "{{ download_timeout }}"
25-
# loop: "{{ code_arm32_release_apk }}"

roles/code/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
include_tasks: install.yml
1818
when: code_installed is undefined
1919

20-
- name: Enable/Disable/Reload NGINX for code, if nginx_enabled
21-
include_tasks: nginx.yml
20+
- name: Enable/Disable/Reload NGINX for COTG
21+
include_tasks: enable-or-disable.yml
2222

2323
- name: Add 'code' variable values to {{ iiab_ini_file }}
2424
ini_file:

roles/code/templates/content/en.md.j2

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,17 @@ To get help at any time, long-press anything to display a brief tooltip with lin
3434

3535
## Download
3636

37-
Code on the Go is updated weekly, the version being hosted on this site is: **{{ cotg_version_raw.stdout }}**
37+
Code on the Go is updated weekly, the version being hosted on this site is: **{{ cotg_version }}**
3838
If you want to get details about the latest release; please visit [https://www.appdevforall.org/codeonthego/](https://www.appdevforall.org/codeonthego/)
3939

4040
<div class="download-button-wrapper">
41-
<a href="static/apk/{{ code_arm64_release_apk[0].filename }}" class="download-button">Download Code on the Go (64-bit ARM devices)</a>
41+
<a href="static/apk/{{ code_apk_64bit_filename }}" class="download-button">Download Code on the Go (64-bit ARM devices)</a>
4242
</div>
4343

44+
<!-- <div class="download-button-wrapper">
45+
<a href="static/apk/{{ code_apk_32bit_filename }}" class="download-button">Download Code on the Go (32-bit ARM devices)</a>
46+
</div> -->
47+
4448
## Online resources
4549

4650
Find some useful resources online to interact with the community of users and developers behind Code on the Go.

roles/code/templates/content/es.md.j2

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ Para obtener ayuda en cualquier momento, mantén pulsado cualquier elemento para
3333

3434
## Descargar
3535

36-
Code on the Go es actualizado semanalmente, la versión siendo alojada por esta página es: **{{ cotg_version_raw.stdout }}**
36+
Code on the Go es actualizado semanalmente, la versión siendo alojada por esta página es: **{{ cotg_version }}**
3737
Si desea conocer los detalles acerca de la versión mas reciente; por favor visite [https://www.appdevforall.org/codeonthego/](https://www.appdevforall.org/codeonthego/)
3838

3939
<div class="download-button-wrapper">
40-
<a href="static/apk/{{ code_arm64_release_apk[0].filename }}" class="download-button">Descargue Code on the Go (dispositivos ARM de 64 bits)</a>
40+
<a href="static/apk/{{ code_apk_64bit_filename }}" class="download-button">Descargue Code on the Go (dispositivos ARM de 64 bits)</a>
4141
</div>
4242

43+
<!-- <div class="download-button-wrapper">
44+
<a href="static/apk/{{ code_apk_32bit_filename }}" class="download-button">Descargue Code on the Go (dispositivos ARM de 32 bits)</a>
45+
</div> -->
46+
4347
## Recursos en línea
4448

4549
Encuentre algunos recursos útiles en línea para interactuar con la comunidad de usuarios y desarrolladores detrás de Code on the Go.

0 commit comments

Comments
 (0)