forked from truemark/hello-world-java
-
Notifications
You must be signed in to change notification settings - Fork 0
100 lines (93 loc) · 3.42 KB
/
build-docker.yml
File metadata and controls
100 lines (93 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
on:
workflow_call:
secrets:
aws_assume_role:
description: "AWS role to assume"
required: false
docker_hub_username:
description: "Docker Hub username"
required: false
docker_hub_password:
description: "Docker Hub password or token"
required: false
inputs:
image_name:
description: "Name of the image"
required: true
type: string
version:
description: "Version of the project"
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
env:
AWS_ASSUME_ROLE: ${{ secrets.aws_assume_role }}
DOCKER_HUB_USERNAME: ${{ secrets.docker_hub_username }}
DOCKER_HUB_PASSWORD: ${{ secrets.docker_hub_password }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v3
- name: Login to Docker Hub
uses: docker/login-action@v2
if: env.DOCKER_HUB_USERNAME != '' && env.DOCKER_HUB_PASSWORD != ''
with:
username: ${{ secrets.docker_hub_username }}
password: ${{ secrets.docker_hub_password }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v2
if: env.AWS_ASSUME_ROLE != ''
with:
role-to-assume: "${{ secrets.aws_assume_role }}"
aws-region: "us-east-1"
- name: Login to ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2
if: env.AWS_ASSUME_ROLE != ''
with:
registry-type: public
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker
run: |
docker buildx build \
--push \
--platform linux/arm64,linux/amd64 \
-f Dockerfile \
-t ${{ inputs.image_name }}:${{ inputs.version }} \
-t ${{ inputs.image_name }}:latest \
.
- name: Copy beta to ECR
uses: truemark/skopeo-copy-action@v1
if: env.AWS_ASSUME_ROLE != ''
with:
src-image: "docker://${{ inputs.image_name }}:${{ inputs.version }}"
dest-image: "docker://public.ecr.aws/${{ inputs.image_name }}:${{ inputs.version }}"
src-username: "${{ secrets.docker_hub_username }}"
src-password: "${{ secrets.docker_hub_password }}"
dest-username: "${{ steps.ecr-login.outputs.docker_username_public_ecr_aws }}"
dest-password: "${{ steps.ecr-login.outputs.docker_password_public_ecr_aws }}"
multi-arch: "all"
- name: Copy latest to ECR
uses: truemark/skopeo-copy-action@v1
with:
src-image: "docker://${{ inputs.image_name }}:latest"
dest-image: "docker://public.ecr.aws/${{ inputs.image_name }}:latest"
src-username: "${{ secrets.docker_hub_username }}"
src-password: "${{ secrets.docker_hub_password }}"
dest-username: "${{ steps.ecr-login.outputs.docker_username_public_ecr_aws }}"
dest-password: "${{ steps.ecr-login.outputs.docker_password_public_ecr_aws }}"
multi-arch: "all"
- name: Create Version Artifact
run: |
echo ${{ inputs.version }} > image-tag.txt
- name: Upload Docker Image Tag
uses: actions/upload-artifact@v3
with:
name: image-tag
path: image-tag.txt