forked from imranismail/relayman
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from kfit-dev/SRE-1362-update-github-workflows-…
…actions-checkout-v-3-to-v-4 bump action/checkout@v2 to action/checkout@v4
- Loading branch information
Showing
2 changed files
with
33 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,31 @@ | ||
name: Build relayman | ||
name: Docker | ||
|
||
on: | ||
push: | ||
# Publish `master` as Docker `latest` image. | ||
branches: | ||
- master | ||
|
||
# Publish `v1.2.3` tags as releases. | ||
tags: | ||
- v* | ||
|
||
# Run tests for any PRs. | ||
pull_request: | ||
|
||
env: | ||
ECR_REGISTRY: 606804169143.dkr.ecr.ap-southeast-1.amazonaws.com | ||
ECR_BUILD_REPO: relayman | ||
|
||
# TODO: Change variable to your image's name. | ||
IMAGE_NAME: relayman | ||
REGISTRY: https://ghcr.io | ||
jobs: | ||
# Run tests. | ||
# See also https://docs.docker.com/docker-hub/builds/automated-testing/ | ||
test: | ||
runs-on: ubuntu-20.04 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Run tests | ||
run: | | ||
if [ -f docker-compose.test.yml ]; then | ||
|
@@ -28,88 +34,32 @@ jobs: | |
else | ||
docker build . --file Dockerfile | ||
fi | ||
setup_env: | ||
if: ${{ github.event_name == 'push' }} | ||
# Push image to GitHub Packages. | ||
# See also https://docs.docker.com/docker-hub/builds/ | ||
push: | ||
# Ensure test job passes before pushing image. | ||
needs: test | ||
environment: test | ||
runs-on: ubuntu-20.04 | ||
outputs: | ||
ecr_password: ${{ steps.ecr_password.outputs.ecr_password }} | ||
container_image_uri: ${{ steps.image_tag.outputs.container_image_uri }} | ||
image_tag: ${{ steps.image_tag.outputs.image_tag }} | ||
steps: | ||
- name: Set up AWS CLI | ||
uses: chrislennon/[email protected] | ||
- id: ecr_password | ||
name: Retrieve ECR password | ||
env: | ||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
AWS_DEFAULT_REGION: ap-southeast-1 | ||
run: echo "ecr_password=$(aws ecr get-login-password)" >> $GITHUB_OUTPUT | ||
- id: image_tag | ||
name: Setup image tags | ||
run: | | ||
IMAGE_TAG=latest | ||
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
echo "container_image_uri=$ECR_REGISTRY/$ECR_BUILD_REPO:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
docker_build: | ||
if: ${{ github.event_name == 'push' }} | ||
timeout-minutes: 40 | ||
needs: | ||
- setup_env | ||
environment: test | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- name: Check Out Repo | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Docker Buildx | ||
id: buildx | ||
uses: docker/setup-buildx-action@v2 | ||
with: | ||
buildkitd-flags: --debug | ||
install: true | ||
runs-on: ubuntu-latest | ||
if: github.event_name == 'push' | ||
|
||
- name: Cache Docker layers | ||
uses: actions/cache@v3 | ||
with: | ||
path: /tmp/.buildx-cache-${{ matrix.gemfile }} | ||
key: ${{ runner.os }}-multi-buildx-${{ github.sha }}-${{ matrix.gemfile }} | ||
restore-keys: | | ||
${{ runner.os }}-multi-buildx | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v1 | ||
with: | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-southeast-1 | ||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME | ||
|
||
- name: Login to ECR | ||
uses: docker/login-action@v2 | ||
- name: Log in to the GitHub Container registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ${{ env.ECR_REGISTRY }} | ||
|
||
- name: Build image | ||
uses: docker/build-push-action@v3 | ||
env: | ||
CONTAINER_IMAGE_URI: ${{ needs.setup_env.outputs.container_image_uri }} | ||
registry: ${{ env.REGISTRY }} | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Build and push Docker image | ||
id: push | ||
uses: docker/build-push-action@v5 | ||
with: | ||
context: . | ||
builder: ${{ steps.buildx.outputs.name }} | ||
file: Dockerfile | ||
push: true | ||
tags: ${{ env.CONTAINER_IMAGE_URI }} | ||
cache-from: type=local,src=/tmp/.buildx-cache-${{ matrix.gemfile }} | ||
# Note the mode=max here | ||
# More: https://github.com/moby/buildkit#--export-cache-options | ||
# And: https://github.com/docker/buildx#--cache-tonametypetypekeyvalue | ||
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new-${{ matrix.gemfile }} | ||
|
||
- name: Move cache | ||
run: | | ||
rm -rf /tmp/.buildx-cache-${{ matrix.gemfile }} | ||
mv /tmp/.buildx-cache-new-${{ matrix.gemfile }} /tmp/.buildx-cache-${{ matrix.gemfile }} | ||
tags: $IMAGE_NAME | ||
labels: $IMAGE_NAME |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters