Skip to content

Commit ab2be14

Browse files
feat(build): add timezone arg for dockerfile (#581)
close #528 --------- Signed-off-by: Adam Vollrath <[email protected]> Co-authored-by: Adam Vollrath <[email protected]>
1 parent 67d1af3 commit ab2be14

7 files changed

+40
-24
lines changed

Diff for: .github/workflows/build-binary-for-release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ permissions:
2626

2727
jobs:
2828
build-goreleaser:
29+
if: ${{ github.repository_owner == 'apache' }}
2930
runs-on: ubuntu-latest
3031

3132
steps:

Diff for: .github/workflows/build-image-for-manual.yml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ on:
2727

2828
jobs:
2929
build:
30+
if: ${{ github.repository_owner == 'apache' }}
3031
runs-on: ubuntu-latest
3132
steps:
3233
- name: Checkout

Diff for: .github/workflows/build-image-for-release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ on:
2929

3030
jobs:
3131
build:
32+
if: ${{ github.repository_owner == 'apache' }}
3233
runs-on: ubuntu-latest
3334
steps:
3435
- name: Checkout

Diff for: .github/workflows/build-image-for-test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ on:
2323

2424
jobs:
2525
build:
26+
if: ${{ github.repository_owner == 'apache' }}
2627
name: Build and Push
2728
runs-on: ubuntu-latest
2829
steps:

Diff for: .github/workflows/uffizzi-build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727
outputs:
2828
tags: ${{ steps.meta.outputs.tags }}
29-
if: ${{ github.event.action != 'closed' }}
29+
if: ${{ github.event.action != 'closed' && github.repository_owner == 'apache' }}
3030
steps:
3131
- name: Checkout git repo
3232
uses: actions/checkout@v4
@@ -36,15 +36,15 @@ jobs:
3636

3737
- name: Generate UUID image name
3838
id: uuid
39-
run: echo "UUID_WORKER=$(uuidgen)" >> $GITHUB_ENV
39+
run: echo "UUID_WORKER=answer-$(uuidgen --time)" >> $GITHUB_ENV
4040

4141
- name: Docker metadata
4242
id: meta
4343
uses: docker/metadata-action@v4
4444
with:
4545
images: registry.uffizzi.com/${{ env.UUID_WORKER }}
4646
tags: |
47-
type=raw,value=60d
47+
type=raw,value=30d
4848
4949
- name: Build and Push Image to registry.uffizzi.com - Uffizzi's ephemeral Registry
5050
uses: docker/build-push-action@v3
@@ -98,7 +98,7 @@ jobs:
9898
delete-preview:
9999
name: Call for Preview Deletion
100100
runs-on: ubuntu-latest
101-
if: ${{ github.event.action == 'closed' }}
101+
if: ${{ github.event.action == 'closed' && github.repository_owner == 'apache' }}
102102
steps:
103103
# If this PR is closing, we will not render a compose file nor pass it to the next workflow.
104104
- name: Serialize PR Event to File

Diff for: .github/workflows/uffizzi-preview.yml

+26-18
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ on:
2424
types:
2525
- completed
2626

27-
2827
jobs:
2928
cache-compose-file:
3029
name: Cache Compose File
3130
runs-on: ubuntu-latest
3231
if: ${{ github.event.workflow_run.conclusion == 'success' }}
3332
outputs:
34-
compose-file-cache-key: ${{ env.HASH }}
35-
pr-number: ${{ env.PR_NUMBER }}
33+
compose-file-cache-key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
34+
git-ref: ${{ steps.event.outputs.GIT_REF }}
35+
pr-number: ${{ steps.event.outputs.PR_NUMBER }}
36+
action: ${{ steps.event.outputs.ACTION }}
3637
steps:
37-
- name: 'Download artifacts'
38+
- name: Download artifacts
3839
# Fetch output (zip archive) from the workflow run that triggered this workflow.
3940
uses: actions/github-script@v6
4041
with:
@@ -47,6 +48,9 @@ jobs:
4748
let matchArtifact = allArtifacts.data.artifacts.filter((artifact) => {
4849
return artifact.name == "preview-spec"
4950
})[0];
51+
if (matchArtifact === undefined) {
52+
throw TypeError('Build Artifact not found!');
53+
}
5054
let download = await github.rest.actions.downloadArtifact({
5155
owner: context.repo.owner,
5256
repo: context.repo.repo,
@@ -56,34 +60,38 @@ jobs:
5660
let fs = require('fs');
5761
fs.writeFileSync(`${process.env.GITHUB_WORKSPACE}/preview-spec.zip`, Buffer.from(download.data));
5862
59-
- name: 'Unzip artifact'
60-
run: unzip preview-spec.zip
63+
- name: 'Accept event from first stage'
64+
run: unzip preview-spec.zip event.json
65+
6166
- name: Read Event into ENV
67+
id: event
6268
run: |
63-
echo 'EVENT_JSON<<EOF' >> $GITHUB_ENV
64-
cat event.json >> $GITHUB_ENV
65-
echo 'EOF' >> $GITHUB_ENV
69+
echo PR_NUMBER=$(jq '.number | tonumber' < event.json) >> $GITHUB_OUTPUT
70+
echo ACTION=$(jq --raw-output '.action | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
71+
echo GIT_REF=$(jq --raw-output '.pull_request.head.sha | tostring | [scan("\\w+")][0]' < event.json) >> $GITHUB_OUTPUT
6672
6773
- name: Hash Rendered Compose File
6874
id: hash
6975
# If the previous workflow was triggered by a PR close event, we will not have a compose file artifact.
70-
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
71-
run: echo "HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_ENV
76+
if: ${{ steps.event.outputs.ACTION != 'closed' }}
77+
run: |
78+
unzip preview-spec.zip docker-compose.rendered.yml
79+
echo "COMPOSE_FILE_HASH=$(md5sum docker-compose.rendered.yml | awk '{ print $1 }')" >> $GITHUB_OUTPUT
80+
7281
- name: Cache Rendered Compose File
73-
if: ${{ fromJSON(env.EVENT_JSON).action != 'closed' }}
82+
if: ${{ steps.event.outputs.ACTION != 'closed' }}
7483
uses: actions/cache@v3
7584
with:
7685
path: docker-compose.rendered.yml
77-
key: ${{ env.HASH }}
86+
key: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}
7887

79-
- name: Read PR Number From Event Object
80-
id: pr
81-
run: echo "PR_NUMBER=${{ fromJSON(env.EVENT_JSON).number }}" >> $GITHUB_ENV
8288
- name: DEBUG - Print Job Outputs
8389
if: ${{ runner.debug }}
8490
run: |
85-
echo "PR number: ${{ env.PR_NUMBER }}"
86-
echo "Compose file hash: ${{ env.HASH }}"
91+
echo "PR number: ${{ steps.event.outputs.PR_NUMBER }}"
92+
echo "Git Ref: ${{ steps.event.outputs.GIT_REF }}"
93+
echo "Action: ${{ steps.event.outputs.ACTION }}"
94+
echo "Compose file hash: ${{ steps.hash.outputs.COMPOSE_FILE_HASH }}"
8795
cat event.json
8896
8997
deploy-uffizzi-preview:

Diff for: Dockerfile

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ RUN mkdir -p /data/uploads && chmod 777 /data/uploads \
4747
FROM alpine
4848
LABEL maintainer="[email protected]"
4949

50-
ENV TZ "Asia/Shanghai"
50+
ARG TIMEZONE
51+
ENV TIMEZONE=${TIMEZONE:-"Asia/Shanghai"}
52+
5153
RUN apk update \
5254
&& apk --no-cache add \
5355
bash \
@@ -58,7 +60,9 @@ RUN apk update \
5860
openssh \
5961
sqlite \
6062
gnupg \
61-
&& echo "Asia/Shanghai" > /etc/timezone
63+
tzdata \
64+
&& ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
65+
&& echo "${TIMEZONE}" > /etc/timezone
6266

6367
COPY --from=golang-builder /usr/bin/answer /usr/bin/answer
6468
COPY --from=golang-builder /data /data

0 commit comments

Comments
 (0)