-
-
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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- name: Lint Dockerfile
uses: hadolint/hadolint-action@2332a7b74a6de0dda2e2221d575162eba76ba5e5 # v3.3.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@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@96fe6ef7f33517b61c61be40b68a1882f3264fb8 # v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4
- name: Log in to Docker Hub
uses: docker/login-action@af1e73f918a031802d376d3c8bbc3fe56130a9b0 # 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@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7
with:
context: .
push: true
tags: drevops/git-artifact:canary
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64