-
-
Notifications
You must be signed in to change notification settings - Fork 2
109 lines (88 loc) 路 3.42 KB
/
Copy pathtest-docker.yml
File metadata and controls
109 lines (88 loc) 路 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
name: Test Docker
on:
push:
branches:
- main
pull_request:
branches:
- main
- 'feature/**'
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
test-docker:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Lint Dockerfile
uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0
- name: Build Docker image
run: docker build -t "drevops/git-artifact:test" .
- name: Test that the image packages and pushes an artifact
run: |
set -ex
src="${RUNNER_TEMP}/src"
dst="${RUNNER_TEMP}/dst.git"
# Prepare a source repository with a tracked file.
mkdir -p "${src}"
git -C "${src}" init -b main
git -C "${src}" config user.name "Test"
git -C "${src}" config user.email "test@example.com"
echo "artifact content" > "${src}/file.txt"
git -C "${src}" add -A
git -C "${src}" commit -m "Initial commit"
# Prepare a bare destination repository to receive the artifact.
git init --bare -b main "${dst}"
# Package and push the artifact from inside the container. The source
# is mounted at the WORKDIR and the destination is mounted as a local
# remote. The commit identity is supplied via the environment (the
# image trusts mounted repositories via a baked-in safe.directory).
docker run --rm \
-e GIT_AUTHOR_NAME="Test" \
-e GIT_AUTHOR_EMAIL="test@example.com" \
-e GIT_COMMITTER_NAME="Test" \
-e GIT_COMMITTER_EMAIL="test@example.com" \
-v "${src}":/app \
-v "${dst}":/dst.git \
drevops/git-artifact:test \
/dst.git --branch=artifact --mode=force-push -vvv
# Assert the file landed on the destination branch.
git -C "${dst}" show artifact:file.txt | grep -q "artifact content"
push-canary-to-registry:
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs:
- test-docker
steps:
- name: Checkout code
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@594f3bf4285d9ea8dc53c9a0c9c4092420091003 # v4
- name: Log in to Docker Hub
uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_PASS }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6
with:
images: drevops/git-artifact
- name: Build and push Docker image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: .
push: true
tags: drevops/git-artifact:canary
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64