Skip to content

Instantly share code, notes, and snippets.

@tk42
Created September 9, 2023 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tk42/d9f772b84bc0a62d28b94877f5a6d2c0 to your computer and use it in GitHub Desktop.
Save tk42/d9f772b84bc0a62d28b94877f5a6d2c0 to your computer and use it in GitHub Desktop.
.github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
env:
GIT_TERMINAL_PROMPT: 1
runs-on: ubuntu-latest
steps:
- name: github private modules access
run: git config --global url."https://${{ secrets.PAT }}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: Set up cache
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- uses: docker/setup-buildx-action@v2
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
# If this fails due to 403 Forbidden, you'll check https://github.com/docker/build-push-action/issues/463#issuecomment-924995909
- uses: docker/build-push-action@v3
with:
context: .
push: true
tags: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:latest
@tk42
Copy link
Author

tk42 commented Sep 9, 2023

GithubのOrganizationSettingsSecrets and variablesActionsPATというSecretsを登録しておいて,Dockerfileをレポジトリのルートに含むレポジトリで,.github/workflows以下に上記をdeploy.ymlとしておくと,mainブランチにpushされるごとにイメージを作ってくれる

@tk42
Copy link
Author

tk42 commented Sep 10, 2023

最初のdeploy(push image)が失敗する時,レポジトリのSettings->Actions->General->Workflow permissionsでRead and write permissions にチェックが入っているか確認

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment