Skip to content

Commit 84e3796

Browse files
authored
new docker action
1 parent 172a4df commit 84e3796

File tree

1 file changed

+43
-45
lines changed

1 file changed

+43
-45
lines changed
Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,51 @@
1-
name: Docker
1+
name: Release Docker Image
22

33
on:
4-
push:
5-
# Publish `main` as Docker `latest` image.
6-
branches:
7-
- main
8-
9-
# Publish `1.2.3` tags as releases.
10-
tags:
11-
- '*'
12-
13-
env:
14-
# TODO: Change variable to your image's name.
15-
IMAGE_NAME: aws-ecs-eds
4+
workflow_dispatch: {}
5+
release:
6+
types: [published]
167

178
jobs:
18-
# Push image to GitHub Packages.
19-
# See also https://docs.docker.com/docker-hub/builds/
20-
push:
9+
push_to_registry:
10+
name: Push Docker image to Docker Hub and ghr
2111
runs-on: ubuntu-latest
22-
23-
2412
steps:
25-
- uses: actions/checkout@v2
26-
27-
- name: Build image
28-
run: docker build . --file Dockerfile --tag $IMAGE_NAME
2913

30-
- name: Login to DockerHub Registry
31-
run: echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
14+
- name: Set up QEMU
15+
uses: docker/[email protected]
16+
17+
- name: Set up Docker Buildx
18+
uses: docker/[email protected]
19+
20+
- name: Check out the repo
21+
uses: actions/[email protected]
22+
23+
- name: Log in to Docker Hub
24+
uses: docker/login-action@v2
25+
with:
26+
username: ${{ secrets.DOCKERHUB_USERNAME }}
27+
password: ${{ secrets.DOCKERHUB_TOKEN }}
3228

33-
- name: Push image
34-
run: |
35-
IMAGE_ID=boostchicken/$IMAGE_NAME
36-
37-
# Change all uppercase to lowercase
38-
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
39-
40-
# Strip git ref prefix from version
41-
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
42-
43-
# Strip "v" prefix from tag name
44-
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
45-
46-
# Use Docker `latest` tag convention
47-
[ "$VERSION" == "main" ] && VERSION=latest
48-
49-
echo IMAGE_ID=$IMAGE_ID
50-
echo VERSION=$VERSION
51-
52-
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION
53-
docker push $IMAGE_ID:$VERSION
29+
- name: Login to GitHub Container Registry
30+
uses: docker/login-action@v2
31+
with:
32+
registry: ghcr.io
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Extract metadata (tags, labels) for Docker
37+
id: meta
38+
uses: docker/metadata-action@v4
39+
with:
40+
images: |
41+
boostchicken/aws-ecs-eds
42+
ghcr.io/boostchicken/aws-ecs-eds
43+
44+
- name: Build and push Docker image
45+
uses: docker/build-push-action@v4
46+
with:
47+
context: .
48+
push: true
49+
platforms: linux/amd64,linux/arm64
50+
tags: ${{ steps.meta.outputs.tags }}
51+
labels: ${{ steps.meta.outputs.labels }}

0 commit comments

Comments
 (0)