Skip to content

Commit 89242e6

Browse files
authored
Merge pull request #895 from MikeMcQuaid/docker
workflows/tests: improve Docker image build and push.
2 parents 84624ee + 8a4e85f commit 89242e6

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

.github/workflows/tests.yml

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,36 +85,50 @@ jobs:
8585
- name: Set up Git repository
8686
uses: actions/checkout@v4
8787

88-
- name: Build and tag Docker image
88+
- name: Set RUBY_VERSION
8989
run: |
90-
set -euo pipefail
91-
92-
docker build --build-arg RUBY_VERSION=$(cat .ruby-version) --tag strap .
93-
docker tag strap mikemcquaid/strap:master
94-
docker tag strap mikemcquaid/strap:main
95-
docker tag strap mikemcquaid/strap:latest
96-
docker tag strap ghcr.io/mikemcquaid/strap:master
97-
docker tag strap ghcr.io/mikemcquaid/strap:main
98-
docker tag strap ghcr.io/mikemcquaid/strap:latest
99-
100-
- name: Deploy the Docker image to GitHub Packages
101-
if: github.ref == 'refs/heads/main'
102-
run: |
103-
set -euo pipefail
90+
set -xeuo pipefail
10491
105-
echo ${{secrets.GITHUB_TOKEN}} | \
106-
docker login --username=mikemcquaid --password-stdin ghcr.io
107-
docker push ghcr.io/mikemcquaid/strap:master
108-
docker push ghcr.io/mikemcquaid/strap:main
109-
docker push ghcr.io/mikemcquaid/strap:latest
92+
RUBY_VERSION=$(cat .ruby-version)
93+
echo "RUBY_VERSION=${RUBY_VERSION}" >> "${GITHUB_ENV}"
11094
111-
- name: Deploy the Docker image to Docker Hub
112-
if: github.ref == 'refs/heads/main'
113-
run: |
114-
set -euo pipefail
95+
- uses: docker/setup-buildx-action@v3
11596

116-
echo ${{secrets.DOCKER_TOKEN}} | \
117-
docker login --username=mikemcquaid --password-stdin
118-
docker push mikemcquaid/strap:master
119-
docker push mikemcquaid/strap:main
120-
docker push mikemcquaid/strap:latest
97+
# We don't give Dependabot access to tokens.
98+
- if: github.actor != 'dependabot[bot]'
99+
name: Login to DigitalOcean
100+
uses: digitalocean/action-doctl@v2
101+
with:
102+
token: ${{ secrets.DIGITAL_OCEAN_TOKEN }}
103+
104+
# We don't give Dependabot access to tokens.
105+
- if: github.actor != 'dependabot[bot]'
106+
name: Login to Docker Hub
107+
uses: docker/login-action@v3
108+
with:
109+
username: mikemcquaid
110+
password: ${{ secrets.DOCKER_TOKEN }}
111+
112+
# We don't give Dependabot access to tokens.
113+
- name: Login to GitHub Packages
114+
uses: docker/login-action@v3
115+
with:
116+
registry: ghcr.io
117+
username: mikemcquaid
118+
password: ${{ secrets.GITHUB_TOKEN }}
119+
120+
- uses: docker/build-push-action@v5
121+
with:
122+
push: ${{ github.ref == 'refs/heads/main' }}
123+
tags: |
124+
mikemcquaid/strap:latest
125+
mikemcquaid/strap:main
126+
mikemcquaid/strap:master
127+
ghcr.io/mikemcquaid/strap:latest
128+
ghcr.io/mikemcquaid/strap:main
129+
ghcr.io/mikemcquaid/strap:master
130+
registry.digitalocean.com/mikemcquaid/strap:latest
131+
cache-from: type=gha
132+
cache-to: type=gha,mode=max
133+
build-args: |
134+
RUBY_VERSION=${{ env.RUBY_VERSION }}

0 commit comments

Comments
 (0)